Class: Slk::Models::Duration
- Inherits:
-
Data
- Object
- Data
- Slk::Models::Duration
- Defined in:
- lib/slk/models/duration.rb
Instance Attribute Summary collapse
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #to_expiration ⇒ Object
- #to_minutes ⇒ Object
- #to_s ⇒ Object
- #zero? ⇒ Boolean
Instance Attribute Details
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds
8 9 10 |
# File 'lib/slk/models/duration.rb', line 8 def seconds @seconds end |
Class Method Details
.from_minutes(minutes) ⇒ Object
19 20 21 |
# File 'lib/slk/models/duration.rb', line 19 def from_minutes(minutes) new(seconds: minutes.to_i * 60) end |
.parse(input) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/slk/models/duration.rb', line 10 def parse(input) return new(seconds: 0) if input.nil? || input.to_s.strip.empty? return new(seconds: input.to_i) if input.to_s.match?(/^\d+$/) parse_duration_string(input.to_s.downcase, input) end |
.zero ⇒ Object
17 |
# File 'lib/slk/models/duration.rb', line 17 def zero = new(seconds: 0) |
Instance Method Details
#+(other) ⇒ Object
64 65 66 |
# File 'lib/slk/models/duration.rb', line 64 def +(other) Duration.new(seconds: seconds + other.seconds) end |
#-(other) ⇒ Object
68 69 70 |
# File 'lib/slk/models/duration.rb', line 68 def -(other) Duration.new(seconds: [seconds - other.seconds, 0].max) end |
#to_expiration ⇒ Object
52 53 54 55 56 |
# File 'lib/slk/models/duration.rb', line 52 def to_expiration return 0 if zero? Time.now.to_i + seconds end |
#to_minutes ⇒ Object
50 |
# File 'lib/slk/models/duration.rb', line 50 def to_minutes = (seconds / 60.0).ceil |
#to_s ⇒ Object
58 59 60 61 62 |
# File 'lib/slk/models/duration.rb', line 58 def to_s return '' if zero? format_duration end |
#zero? ⇒ Boolean
48 |
# File 'lib/slk/models/duration.rb', line 48 def zero? = seconds.zero? |