instance method
normalize
Ruby on Rails 5.0.7.2
Since v5.0.7.2 Last seen in v5.0.7.2 Private — implementation detail, not part of the public APISignature
normalize()
Return pair of duration’s parts and whole duration sign. Parts are summarized (as they can become repetitive due to addition, etc). Zero parts are removed as not significant. If all parts are negative it will negate all of them and return minus as a sign.
Source
# File activesupport/lib/active_support/duration/iso8601_serializer.rb, line 37
def normalize
parts = @duration.parts.each_with_object(Hash.new(0)) do |(k,v),p|
p[k] += v unless v.zero?
end
# If all parts are negative - let's make a negative duration
sign = ''
if parts.values.all? { |v| v < 0 }
sign = '-'
parts.transform_values!(&:-@)
end
[parts, sign]
end
Defined in activesupport/lib/active_support/duration/iso8601_serializer.rb line 37
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Duration::ISO8601Serializer