Class: Biz::Duration
Class Method Summary collapse
- .hours(hours) ⇒ Object (also: hour)
- .minutes(minutes) ⇒ Object (also: minute)
- .seconds(seconds) ⇒ Object (also: second)
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #abs ⇒ Object
- #in_hours ⇒ Object
- #in_minutes ⇒ Object
- #in_seconds ⇒ Object
-
#initialize(seconds) ⇒ Duration
constructor
A new instance of Duration.
- #positive? ⇒ Boolean
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 |
#abs ⇒ Object
58 59 60 |
# File 'lib/biz/duration.rb', line 58 def abs self.class.new(seconds.abs) end |
#in_hours ⇒ Object
42 43 44 |
# File 'lib/biz/duration.rb', line 42 def in_hours seconds / Time.hour_seconds end |
#in_minutes ⇒ Object
38 39 40 |
# File 'lib/biz/duration.rb', line 38 def in_minutes seconds / Time.minute_seconds end |
#in_seconds ⇒ Object
34 35 36 |
# File 'lib/biz/duration.rb', line 34 def in_seconds seconds end |
#positive? ⇒ Boolean
54 55 56 |
# File 'lib/biz/duration.rb', line 54 def positive? seconds.positive? end |