Class: DOTIW::TimeHash

Inherits:
Object
  • Object
show all
Defined in:
lib/dotiw/time_hash.rb

Constant Summary collapse

TIME_FRACTIONS =
[:seconds, :minutes, :hours, :days, :months, :years]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(distance, from_time = nil, to_time = nil, options = {}) ⇒ TimeHash

Returns a new instance of TimeHash.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dotiw/time_hash.rb', line 9

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

  I18n.locale = options[:locale] if options[:locale]

  build_time_hash
end

Instance Attribute Details

#distanceObject

Returns the value of attribute distance.



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

def distance
  @distance
end

#from_timeObject

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

Returns the value of attribute largest.



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

def largest
  @largest
end

#smallestObject

Returns the value of attribute smallest.



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

def smallest
  @smallest
end

#to_timeObject

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



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

def to_hash
  output
end