Class: DOTIW::TimeHash
- Inherits:
-
Object
- Object
- DOTIW::TimeHash
- Defined in:
- lib/dotiw/time_hash.rb
Constant Summary collapse
- TIME_FRACTIONS =
%i[seconds minutes hours days weeks months years].freeze
Instance Attribute Summary collapse
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#from_time ⇒ Object
readonly
Returns the value of attribute from_time.
-
#largest ⇒ Object
readonly
Returns the value of attribute largest.
-
#smallest ⇒ Object
readonly
Returns the value of attribute smallest.
-
#to_time ⇒ Object
readonly
Returns the value of attribute to_time.
Instance Method Summary collapse
-
#initialize(distance, from_time, to_time = nil, options = {}) ⇒ TimeHash
constructor
A new instance of TimeHash.
- #to_hash ⇒ Object
Constructor Details
#initialize(distance, from_time, to_time = nil, options = {}) ⇒ TimeHash
Returns a new instance of TimeHash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dotiw/time_hash.rb', line 9 def initialize(distance, from_time, to_time = nil, = {}) @output = {} @options = .dup @distance = distance @from_time = from_time || Time.current @to_time = to_time || (@to_time_not_given = true && @from_time + distance.seconds) @smallest, @largest = [@from_time, @to_time].minmax @to_time += 1.hour if @to_time_not_given && smallest.dst? && !largest.dst? @to_time -= 1.hour if @to_time_not_given && !smallest.dst? && largest.dst? @smallest, @largest = [@from_time, @to_time].minmax @distance ||= begin d = largest - smallest d -= 1.hour if smallest.dst? && !largest.dst? d += 1.hour if !smallest.dst? && largest.dst? d end build_time_hash end |
Instance Attribute Details
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
7 8 9 |
# File 'lib/dotiw/time_hash.rb', line 7 def distance @distance end |
#from_time ⇒ Object (readonly)
Returns the value of attribute from_time.
7 8 9 |
# File 'lib/dotiw/time_hash.rb', line 7 def from_time @from_time end |
#largest ⇒ Object (readonly)
Returns the value of attribute largest.
7 8 9 |
# File 'lib/dotiw/time_hash.rb', line 7 def largest @largest end |
#smallest ⇒ Object (readonly)
Returns the value of attribute smallest.
7 8 9 |
# File 'lib/dotiw/time_hash.rb', line 7 def smallest @smallest end |
#to_time ⇒ Object (readonly)
Returns the value of attribute to_time.
7 8 9 |
# File 'lib/dotiw/time_hash.rb', line 7 def to_time @to_time end |
Instance Method Details
#to_hash ⇒ Object
29 30 31 |
# File 'lib/dotiw/time_hash.rb', line 29 def to_hash output end |