diff options
author | Xavier Noria <fxn@hashref.com> | 2016-08-06 17:58:50 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-08-06 18:10:53 +0200 |
commit | d66e7835bea9505f7003e5038aa19b6ea95ceea1 (patch) | |
tree | 9846f86c6d130595f54c389c83b66d57101563c5 /activesupport/lib/active_support/duration | |
parent | 77eb40dab64e1fe2a759044d4f122dc0ef833141 (diff) | |
download | rails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.tar.gz rails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.tar.bz2 rails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.zip |
applies new string literal convention in activesupport/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
Diffstat (limited to 'activesupport/lib/active_support/duration')
-rw-r--r-- | activesupport/lib/active_support/duration/iso8601_parser.rb | 22 | ||||
-rw-r--r-- | activesupport/lib/active_support/duration/iso8601_serializer.rb | 12 |
2 files changed, 17 insertions, 17 deletions
diff --git a/activesupport/lib/active_support/duration/iso8601_parser.rb b/activesupport/lib/active_support/duration/iso8601_parser.rb index 12515633fc..3f113b1ef0 100644 --- a/activesupport/lib/active_support/duration/iso8601_parser.rb +++ b/activesupport/lib/active_support/duration/iso8601_parser.rb @@ -1,5 +1,5 @@ -require 'strscan' -require 'active_support/core_ext/regexp' +require "strscan" +require "active_support/core_ext/regexp" module ActiveSupport class Duration @@ -12,8 +12,8 @@ module ActiveSupport class ParsingError < ::ArgumentError; end PERIOD_OR_COMMA = /\.|,/ - PERIOD = '.'.freeze - COMMA = ','.freeze + PERIOD = ".".freeze + COMMA = ",".freeze SIGN_MARKER = /\A\-|\+|/ DATE_MARKER = /P/ @@ -21,8 +21,8 @@ module ActiveSupport DATE_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(Y|M|D|W)/ TIME_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(H|M|S)/ - DATE_TO_PART = { 'Y' => :years, 'M' => :months, 'W' => :weeks, 'D' => :days } - TIME_TO_PART = { 'H' => :hours, 'M' => :minutes, 'S' => :seconds } + DATE_TO_PART = { "Y" => :years, "M" => :months, "W" => :weeks, "D" => :days } + TIME_TO_PART = { "H" => :hours, "M" => :minutes, "S" => :seconds } DATE_COMPONENTS = [:years, :months, :days] TIME_COMPONENTS = [:hours, :minutes, :seconds] @@ -42,7 +42,7 @@ module ActiveSupport case mode when :start if scan(SIGN_MARKER) - self.sign = (scanner.matched == '-') ? -1 : 1 + self.sign = (scanner.matched == "-") ? -1 : 1 self.mode = :sign else raise_parsing_error @@ -99,21 +99,21 @@ module ActiveSupport # Checks for various semantic errors as stated in ISO 8601 standard. def validate! - raise_parsing_error('is empty duration') if parts.empty? + raise_parsing_error("is empty duration") if parts.empty? # Mixing any of Y, M, D with W is invalid. if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any? - raise_parsing_error('mixing weeks with other date parts not allowed') + raise_parsing_error("mixing weeks with other date parts not allowed") end # Specifying an empty T part is invalid. if mode == :time && (parts.keys & TIME_COMPONENTS).empty? - raise_parsing_error('time part marker is present but time part is empty') + raise_parsing_error("time part marker is present but time part is empty") end fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 } unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last) - raise_parsing_error '(only last part can be fractional)' + raise_parsing_error "(only last part can be fractional)" end return true diff --git a/activesupport/lib/active_support/duration/iso8601_serializer.rb b/activesupport/lib/active_support/duration/iso8601_serializer.rb index eb8136e208..542630b950 100644 --- a/activesupport/lib/active_support/duration/iso8601_serializer.rb +++ b/activesupport/lib/active_support/duration/iso8601_serializer.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/hash/transform_values' +require "active_support/core_ext/object/blank" +require "active_support/core_ext/hash/transform_values" module ActiveSupport class Duration @@ -15,12 +15,12 @@ module ActiveSupport parts, sign = normalize return "PT0S".freeze if parts.empty? - output = 'P' + output = "P" output << "#{parts[:years]}Y" if parts.key?(:years) output << "#{parts[:months]}M" if parts.key?(:months) output << "#{parts[:weeks]}W" if parts.key?(:weeks) output << "#{parts[:days]}D" if parts.key?(:days) - time = '' + time = "" time << "#{parts[:hours]}H" if parts.key?(:hours) time << "#{parts[:minutes]}M" if parts.key?(:minutes) if parts.key?(:seconds) @@ -41,9 +41,9 @@ module ActiveSupport p[k] += v unless v.zero? end # If all parts are negative - let's make a negative duration - sign = '' + sign = "" if parts.values.all? { |v| v < 0 } - sign = '-' + sign = "-" parts.transform_values!(&:-@) end [parts, sign] |