Class: Clef::Ir::Moment

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/clef/ir/moment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Moment

Returns a new instance of Moment.

Parameters:

  • value (Rational, Integer)


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

#valueObject (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

Parameters:

  • duration (Rational, #length)

Returns:



19
20
21
# File 'lib/clef/ir/moment.rb', line 19

def +(other)
  self.class.new(value + normalize_duration(other))
end

#-(other) ⇒ Rational

Parameters:

  • other (Moment, Rational, Integer)

Returns:

  • (Rational)


25
26
27
# File 'lib/clef/ir/moment.rb', line 25

def -(other)
  value - normalize_other(other)
end

#<=>(other) ⇒ Integer?

Parameters:

Returns:

  • (Integer, nil)


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

Returns:

  • (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

#hashObject



37
38
39
# File 'lib/clef/ir/moment.rb', line 37

def hash
  value.hash
end