Class: Biz::Duration

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ Duration

Returns a new instance of Duration.



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

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

Class Method Details

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



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

def hours(hours)
  new(hours * Time.hour_seconds)
end

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



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

def minutes(minutes)
  new(minutes * Time.minute_seconds)
end

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



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

def seconds(seconds)
  new(seconds)
end

Instance Method Details

#+(other) ⇒ Object



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

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

#-(other) ⇒ Object



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

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

#absObject



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

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

#in_hoursObject



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

def in_hours
  seconds / Time.hour_seconds
end

#in_minutesObject



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

def in_minutes
  seconds / Time.minute_seconds
end

#in_secondsObject



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

def in_seconds
  seconds
end

#positive?Boolean

Returns:

  • (Boolean)


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

def positive?
  seconds.positive?
end