aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/duration/iso8601_parser.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 17:58:50 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:10:53 +0200
commitd66e7835bea9505f7003e5038aa19b6ea95ceea1 (patch)
tree9846f86c6d130595f54c389c83b66d57101563c5 /activesupport/lib/active_support/duration/iso8601_parser.rb
parent77eb40dab64e1fe2a759044d4f122dc0ef833141 (diff)
downloadrails-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/iso8601_parser.rb')
-rw-r--r--activesupport/lib/active_support/duration/iso8601_parser.rb22
1 files changed, 11 insertions, 11 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