Class: Clef::Ir::Moment
- Inherits:
-
Object
- Object
- Clef::Ir::Moment
- Includes:
- Comparable
- Defined in:
- lib/clef/ir/moment.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #+(other) ⇒ Moment
- #-(other) ⇒ Rational
- #<=>(other) ⇒ Integer?
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(value) ⇒ Moment
constructor
A new instance of Moment.
Constructor Details
#initialize(value) ⇒ Moment
Returns a new instance of Moment.
11 12 13 14 15 |
# File 'lib/clef/ir/moment.rb', line 11 def initialize(value) @value = Rational(value) rescue TypeError raise ArgumentError, "moment value must be Rational-compatible" end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/clef/ir/moment.rb', line 8 def value @value end |
Instance Method Details
#+(other) ⇒ Moment
19 20 21 |
# File 'lib/clef/ir/moment.rb', line 19 def +(other) self.class.new(value + normalize_duration(other)) end |
#-(other) ⇒ Rational
25 26 27 |
# File 'lib/clef/ir/moment.rb', line 25 def -(other) value - normalize_other(other) end |
#<=>(other) ⇒ Integer?
31 32 33 34 35 |
# File 'lib/clef/ir/moment.rb', line 31 def <=>(other) return nil unless other.is_a?(self.class) value <=> other.value end |
#eql?(other) ⇒ Boolean
41 42 43 |
# File 'lib/clef/ir/moment.rb', line 41 def eql?(other) other.is_a?(self.class) && value.eql?(other.value) end |
#hash ⇒ Object
37 38 39 |
# File 'lib/clef/ir/moment.rb', line 37 def hash value.hash end |