Class: Whenever::NumericSeconds

Inherits:
Object
  • Object
show all
Defined in:
lib/whenever/numeric_seconds.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ NumericSeconds

Returns a new instance of NumericSeconds.



9
10
11
# File 'lib/whenever/numeric_seconds.rb', line 9

def initialize(number)
  @number = number.to_i
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/whenever/numeric_seconds.rb', line 3

def number
  @number
end

Class Method Details

.seconds(number, units) ⇒ Object



5
6
7
# File 'lib/whenever/numeric_seconds.rb', line 5

def self.seconds(number, units)
  new(number).send(units)
end

Instance Method Details

#daysObject Also known as: day



28
29
30
# File 'lib/whenever/numeric_seconds.rb', line 28

def days
  number * 86_400
end

#hoursObject Also known as: hour



23
24
25
# File 'lib/whenever/numeric_seconds.rb', line 23

def hours
  number * 3_600
end

#minutesObject Also known as: minute



18
19
20
# File 'lib/whenever/numeric_seconds.rb', line 18

def minutes
  number * 60
end

#monthsObject Also known as: month



38
39
40
# File 'lib/whenever/numeric_seconds.rb', line 38

def months
  number * 2_592_000
end

#secondsObject Also known as: second



13
14
15
# File 'lib/whenever/numeric_seconds.rb', line 13

def seconds
  number
end

#weeksObject Also known as: week



33
34
35
# File 'lib/whenever/numeric_seconds.rb', line 33

def weeks
  number * 604_800
end

#yearsObject Also known as: year



43
44
45
# File 'lib/whenever/numeric_seconds.rb', line 43

def years
  number * 31_557_600
end