Class: Biz::Duration
- Inherits:
-
Object
- Object
- Biz::Duration
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/biz/duration.rb
Instance Attribute Summary collapse
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
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
- #coerce(other) ⇒ 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.
35 36 37 |
# File 'lib/biz/duration.rb', line 35 def initialize(seconds) @seconds = Integer(seconds) end |
Instance Attribute Details
#seconds ⇒ Object (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 |
#abs ⇒ Object
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_hours ⇒ Object
47 48 49 |
# File 'lib/biz/duration.rb', line 47 def in_hours seconds / Time::HOUR end |
#in_minutes ⇒ Object
43 44 45 |
# File 'lib/biz/duration.rb', line 43 def in_minutes seconds / Time::MINUTE end |
#in_seconds ⇒ Object
39 40 41 |
# File 'lib/biz/duration.rb', line 39 def in_seconds seconds end |
#positive? ⇒ Boolean
59 60 61 |
# File 'lib/biz/duration.rb', line 59 def positive? seconds > 0 end |