Class: Biz::Duration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/biz/duration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ Duration

Returns a new instance of Duration.



35
36
37
# File 'lib/biz/duration.rb', line 35

def initialize(seconds)
  @seconds = Integer(seconds)
end

Instance Attribute Details

#secondsObject (readonly)

Returns the value of attribute seconds.



31
32
33
# File 'lib/biz/duration.rb', line 31

def seconds
  @seconds
end

Class Method Details

.hours(hours) ⇒ Object Also known as: hour



23
24
25
# File 'lib/biz/duration.rb', line 23

def hours(hours)
  new(hours * Time::HOUR)
end

.minutes(minutes) ⇒ Object Also known as: minute



17
18
19
# File 'lib/biz/duration.rb', line 17

def minutes(minutes)
  new(minutes * Time::MINUTE)
end

.seconds(seconds) ⇒ Object Also known as: second



11
12
13
# File 'lib/biz/duration.rb', line 11

def seconds(seconds)
  new(seconds)
end

Instance Method Details

#+(other) ⇒ Object



51
52
53
# File 'lib/biz/duration.rb', line 51

def +(other)
  self.class.new(seconds + other.seconds)
end

#-(other) ⇒ Object



55
56
57
# File 'lib/biz/duration.rb', line 55

def -(other)
  self.class.new(seconds - other.seconds)
end

#absObject



63
64
65
# File 'lib/biz/duration.rb', line 63

def abs
  self.class.new(seconds.abs)
end

#coerce(other) ⇒ Object



67
68
69
# File 'lib/biz/duration.rb', line 67

def coerce(other)
  [self.class.new(other), self]
end

#in_hoursObject



47
48
49
# File 'lib/biz/duration.rb', line 47

def in_hours
  seconds / Time::HOUR
end

#in_minutesObject



43
44
45
# File 'lib/biz/duration.rb', line 43

def in_minutes
  seconds / Time::MINUTE
end

#in_secondsObject



39
40
41
# File 'lib/biz/duration.rb', line 39

def in_seconds
  seconds
end

#positive?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/biz/duration.rb', line 59

def positive?
  seconds > 0
end