Class: Transport::Duration
- Inherits:
-
Object
- Object
- Transport::Duration
- Defined in:
- lib/duration.rb
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
-
#initialize(duration) ⇒ Duration
constructor
A new instance of Duration.
- #to_s ⇒ Object
Constructor Details
#initialize(duration) ⇒ Duration
Returns a new instance of Duration.
9 10 11 12 13 14 15 |
# File 'lib/duration.rb', line 9 def initialize(duration) @days, @hours, @minutes, @seconds = duration.split(/d|:/) @seconds = @seconds.to_i @minutes = @minutes.to_i @hours = @hours.to_i @days = @days.to_i end |
Instance Attribute Details
#days ⇒ Object (readonly)
Returns the value of attribute days.
7 8 9 |
# File 'lib/duration.rb', line 7 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
7 8 9 |
# File 'lib/duration.rb', line 7 def hours @hours end |
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
7 8 9 |
# File 'lib/duration.rb', line 7 def minutes @minutes end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
7 8 9 |
# File 'lib/duration.rb', line 7 def seconds @seconds end |
Instance Method Details
#to_s ⇒ Object
17 18 19 20 21 22 |
# File 'lib/duration.rb', line 17 def to_s result = "" result += "#{@days}d" if @days > 0 result += "#{@hours}h" if @hours > 0 || @days > 0 result += "#{@minutes}m" end |