Class: DOTIW::TimeHash

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
# File 'lib/dotiw/time_hash.rb', line 9

def initialize(distance, from_time, to_time = nil, options = {})
  @output     = {}
  @options    = options.dup
  @distance   = distance
  @from_time  = from_time || Time.current
  @to_time    = to_time || (@from_time + distance.seconds)
  @smallest, @largest = [@from_time, @to_time].minmax
  @distance ||= largest - smallest

  build_time_hash
end

Instance Attribute Details

#distanceObject (readonly)

Returns the value of attribute distance.



7
8
9
# File 'lib/dotiw/time_hash.rb', line 7

def distance
  @distance
end

#from_timeObject (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

#largestObject (readonly)

Returns the value of attribute largest.



7
8
9
# File 'lib/dotiw/time_hash.rb', line 7

def largest
  @largest
end

#smallestObject (readonly)

Returns the value of attribute smallest.



7
8
9
# File 'lib/dotiw/time_hash.rb', line 7

def smallest
  @smallest
end

#to_timeObject (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_hashObject



21
22
23
# File 'lib/dotiw/time_hash.rb', line 21

def to_hash
  output
end