Class: Time::Beat
- Inherits:
-
Object
- Object
- Time::Beat
- Includes:
- Comparable
- Defined in:
- lib/time/beat.rb,
lib/time/beat/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#beats ⇒ Object
Returns the value of attribute beats.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(beats = BigDecimal("0.0")) ⇒ Beat
constructor
A new instance of Beat.
- #to_s ⇒ Object
- #to_time ⇒ Object
Constructor Details
#initialize(beats = BigDecimal("0.0")) ⇒ Beat
Returns a new instance of Beat.
33 34 35 36 37 |
# File 'lib/time/beat.rb', line 33 def initialize(beats = BigDecimal("0.0")) raise "beat value out of range" unless beats >= 0 && beats < 1000 self.beats = beats end |
Instance Attribute Details
#beats ⇒ Object
Returns the value of attribute beats.
31 32 33 |
# File 'lib/time/beat.rb', line 31 def beats @beats end |
Class Method Details
.from_str(s) ⇒ Object
19 20 21 22 23 |
# File 'lib/time/beat.rb', line 19 def self.from_str(s) m = /^@(\d{3}\.\d{3})$/.match(s) raise "invalid beat string" if m.nil? Time::Beat.new(BigDecimal(m.captures.first)) end |
.from_time(t) ⇒ Object
13 14 15 16 17 |
# File 'lib/time/beat.rb', line 13 def self.from_time(t) t = t.utc offset = t.sec + (t.min * 60) + (t.hour * 3600) Time::Beat.new(BigDecimal(offset) / BigDecimal("86.4")) end |
.now ⇒ Object
25 26 27 |
# File 'lib/time/beat.rb', line 25 def self.now from_time(Time.now) end |
Instance Method Details
#<=>(other) ⇒ Object
39 40 41 |
# File 'lib/time/beat.rb', line 39 def <=>(other) beats <=> other.beats end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/time/beat.rb', line 43 def to_s format("@%03d.%03d", beats.truncate, (1000 * beats.frac).round) end |