Class: TimeLord::Period

Inherits:
Object
  • Object
show all
Defined in:
lib/time-lord/period.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(beginning, ending) ⇒ Period

Returns a new instance of Period.



5
6
7
8
# File 'lib/time-lord/period.rb', line 5

def initialize(beginning, ending)
  self.beginning = beginning
  self.ending = ending
end

Instance Attribute Details

#beginningObject



28
29
30
# File 'lib/time-lord/period.rb', line 28

def beginning
  @beginning.to_i
end

#endingObject



32
33
34
# File 'lib/time-lord/period.rb', line 32

def ending
  @ending.to_i
end

Instance Method Details

#differenceObject Also known as: to_i



15
16
17
# File 'lib/time-lord/period.rb', line 15

def difference
  beginning - ending
end

#to_rangeObject



24
25
26
# File 'lib/time-lord/period.rb', line 24

def to_range
  beginning..ending
end

#to_timeObject



20
21
22
# File 'lib/time-lord/period.rb', line 20

def to_time
  if difference < 0 then @beginning else @ending end
end

#to_wordsObject Also known as: in_words



10
11
12
# File 'lib/time-lord/period.rb', line 10

def to_words
  "#{value} #{unit} #{tense}"
end