Class: Tonal::Interval
- Inherits:
-
Object
- Object
- Tonal::Interval
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/tonal/interval.rb
Constant Summary collapse
- INTERVAL_OF_EQUIVALENCE =
2
Instance Attribute Summary collapse
-
#interval ⇒ Object
(also: #ratio)
readonly
Returns the value of attribute interval.
-
#lower_ratio ⇒ Object
(also: #lower)
readonly
Returns the value of attribute lower_ratio.
-
#upper_ratio ⇒ Object
(also: #upper)
readonly
Returns the value of attribute upper_ratio.
Instance Method Summary collapse
- #<=>(rhs) ⇒ Object
- #denominize ⇒ Object
-
#initialize(upper_ratio, lower_ratio) ⇒ Interval
constructor
A new instance of Interval.
- #inspect ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(upper_ratio, lower_ratio) ⇒ Interval
Returns a new instance of Interval.
11 12 13 14 15 |
# File 'lib/tonal/interval.rb', line 11 def initialize(upper_ratio, lower_ratio) @lower_ratio = lower_ratio.ratio @upper_ratio = upper_ratio.ratio @interval = @upper_ratio / @lower_ratio end |
Instance Attribute Details
#interval ⇒ Object (readonly) Also known as: ratio
Returns the value of attribute interval.
7 8 9 |
# File 'lib/tonal/interval.rb', line 7 def interval @interval end |
#lower_ratio ⇒ Object (readonly) Also known as: lower
Returns the value of attribute lower_ratio.
7 8 9 |
# File 'lib/tonal/interval.rb', line 7 def lower_ratio @lower_ratio end |
#upper_ratio ⇒ Object (readonly) Also known as: upper
Returns the value of attribute upper_ratio.
7 8 9 |
# File 'lib/tonal/interval.rb', line 7 def upper_ratio @upper_ratio end |
Instance Method Details
#<=>(rhs) ⇒ Object
36 37 38 |
# File 'lib/tonal/interval.rb', line 36 def <=>(rhs) interval.to_r <=> rhs.interval.to_r end |
#denominize ⇒ Object
26 27 28 29 30 |
# File 'lib/tonal/interval.rb', line 26 def denominize ratios = to_a lcm = ratios.denominators.lcm ratios.map{|r| Tonal::Ratio.new(lcm / r.denominator * r.numerator, lcm)} end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/tonal/interval.rb', line 32 def inspect "#{self.to_r} (#{upper.to_r} / #{lower.to_r})" end |
#to_a ⇒ Object
22 23 24 |
# File 'lib/tonal/interval.rb', line 22 def to_a [lower_ratio, upper_ratio] end |