Class: OSC::TimeTag
- Inherits:
-
Object
- Object
- OSC::TimeTag
- Defined in:
- lib/osc.rb
Overview
64-bit big-endian fixed-point time tag
Constant Summary collapse
- JAN_1970 =
0x83aa7e80
Instance Attribute Summary collapse
-
#frac ⇒ Object
Returns the value of attribute frac.
-
#int ⇒ Object
Returns the value of attribute int.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ TimeTag
constructor
- nil
- immediately Numeric
- seconds since January 1, 1900 00:00 Numeric,Numeric
-
int,frac parts of a TimeTag.
- #method_missing(sym, *args) ⇒ Object
-
#to_a ⇒ Object
[int,frac].
-
#to_f ⇒ Object
Ruby’s Float can handle the 64 bits so we have the luxury of dealing with Float directly.
- #to_i ⇒ Object
-
#to_s ⇒ Object
Human-readable, like the output of Time#to_s.
-
#to_time ⇒ Object
(also: #time)
Ruby Time object.
- #to_yaml ⇒ Object
Constructor Details
#initialize(*args) ⇒ TimeTag
- nil
-
immediately
- Numeric
-
seconds since January 1, 1900 00:00
- Numeric,Numeric
-
int,frac parts of a TimeTag.
- Time
-
convert from Time object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/osc.rb', line 42 def initialize(*args) t = args t = t.first if t and t.size == 1 case t when NIL # immediately @int = 0 @frac = 1 when Numeric @int, fr = t.divmod(1) @frac = (fr * (2**32)).to_i when Array @int,@frac = t when Time @int, fr = (t.to_f+JAN_1970).divmod(1) @frac = (fr * (2**32)).to_i else raise ArgumentError end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
74 75 76 |
# File 'lib/osc.rb', line 74 def method_missing(sym, *args) time.__send__(sym, *args) end |
Instance Attribute Details
#frac ⇒ Object
Returns the value of attribute frac.
61 62 63 |
# File 'lib/osc.rb', line 61 def frac @frac end |
#int ⇒ Object
Returns the value of attribute int.
61 62 63 |
# File 'lib/osc.rb', line 61 def int @int end |
Class Method Details
Instance Method Details
#to_a ⇒ Object
- int,frac
67 |
# File 'lib/osc.rb', line 67 def to_a; [@int,@frac]; end |
#to_f ⇒ Object
Ruby’s Float can handle the 64 bits so we have the luxury of dealing with Float directly
65 |
# File 'lib/osc.rb', line 65 def to_f; @int.to_f + @frac.to_f/(2**32); end |
#to_i ⇒ Object
62 |
# File 'lib/osc.rb', line 62 def to_i; to_f.to_i; end |
#to_s ⇒ Object
Human-readable, like the output of Time#to_s
69 |
# File 'lib/osc.rb', line 69 def to_s; to_time.to_s; end |
#to_time ⇒ Object Also known as: time
Ruby Time object
71 |
# File 'lib/osc.rb', line 71 def to_time; Time.at(to_f-JAN_1970); end |
#to_yaml ⇒ Object
77 78 79 |
# File 'lib/osc.rb', line 77 def to_yaml to_a.to_yaml end |