Class: TimeRange
- Inherits:
-
Object
- Object
- TimeRange
- Defined in:
- lib/rsrt/time_range.rb
Instance Attribute Summary collapse
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#millieseconds ⇒ Object
Returns the value of attribute millieseconds.
-
#minutes ⇒ Object
Returns the value of attribute minutes.
-
#seconds ⇒ Object
Returns the value of attribute seconds.
Instance Method Summary collapse
- #from_ms(ms) ⇒ Object
-
#initialize(time) ⇒ TimeRange
constructor
A new instance of TimeRange.
- #to_ms ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(time) ⇒ TimeRange
Returns a new instance of TimeRange.
5 6 7 8 |
# File 'lib/rsrt/time_range.rb', line 5 def initialize(time) @time = time parse end |
Instance Attribute Details
#hours ⇒ Object
Returns the value of attribute hours.
3 4 5 |
# File 'lib/rsrt/time_range.rb', line 3 def hours @hours end |
#millieseconds ⇒ Object
Returns the value of attribute millieseconds.
3 4 5 |
# File 'lib/rsrt/time_range.rb', line 3 def millieseconds @millieseconds end |
#minutes ⇒ Object
Returns the value of attribute minutes.
3 4 5 |
# File 'lib/rsrt/time_range.rb', line 3 def minutes @minutes end |
#seconds ⇒ Object
Returns the value of attribute seconds.
3 4 5 |
# File 'lib/rsrt/time_range.rb', line 3 def seconds @seconds end |
Instance Method Details
#from_ms(ms) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rsrt/time_range.rb', line 14 def from_ms(ms) t = Time.at(ms/1000) @hours = t.hour - 1 #epoch was at 01:00:00! @minutes = t.min @seconds = t.sec @millieseconds = ms.to_s.reverse.slice(0,3).reverse.to_i end |
#to_ms ⇒ Object
10 11 12 |
# File 'lib/rsrt/time_range.rb', line 10 def to_ms @millieseconds + (@seconds * 1000) + (@minutes * 60000) + (@hours * 3600000) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/rsrt/time_range.rb', line 22 def to_s hours_to_s + ":" + minutes_to_s + ":" + seconds_to_s + "," + millieseconds_to_s end |