Class: TimeRange

Inherits:
Object
  • Object
show all
Defined in:
lib/rsrt/time_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hoursObject

Returns the value of attribute hours.



3
4
5
# File 'lib/rsrt/time_range.rb', line 3

def hours
  @hours
end

#milliesecondsObject

Returns the value of attribute millieseconds.



3
4
5
# File 'lib/rsrt/time_range.rb', line 3

def millieseconds
  @millieseconds
end

#minutesObject

Returns the value of attribute minutes.



3
4
5
# File 'lib/rsrt/time_range.rb', line 3

def minutes
  @minutes
end

#secondsObject

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_msObject



10
11
12
# File 'lib/rsrt/time_range.rb', line 10

def to_ms
  @millieseconds + (@seconds * 1000) + (@minutes * 60000) + (@hours * 3600000)
end

#to_sObject



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