Class: Tonal::ReducedRatio

Inherits:
Ratio
  • Object
show all
Defined in:
lib/tonal/reduced_ratio.rb

Constant Summary collapse

IDENTITY_RATIO =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(antecedent, consequent = 1, label: nil, equave: 2) ⇒ Tonal::ReducedRatio

Examples:

Tonal::ReducedRatio.new(12,2) => 3/2

Parameters:



11
12
13
14
# File 'lib/tonal/reduced_ratio.rb', line 11

def initialize(antecedent, consequent=1, label: nil, equave: 2/1r)
  super(antecedent, consequent, label: label, equave: equave)
  @antecedent, @consequent = @reduced_antecedent, @reduced_consequent
end

Class Method Details

.identityObject



16
17
18
# File 'lib/tonal/reduced_ratio.rb', line 16

def self.identity
  self.new(IDENTITY_RATIO)
end

Instance Method Details

#invert!Tonal::ReducedRatio

Returns with antecedent and precedent switched.

Examples:

Tonal::ReducedRatio.new(3,2).invert! => (4/3)

Returns:



32
33
34
35
36
# File 'lib/tonal/reduced_ratio.rb', line 32

def invert!
  super
  @antecedent, @consequent = @reduced_antecedent, @reduced_consequent
  self
end

#to_basic_ratioTonal::Ratio

Returns self as an instance of unreduced ratio.

Examples:

Tonal::ReducedRatio.new(3,2).to_basic_ratio => (3/2)

Returns:



24
25
26
# File 'lib/tonal/reduced_ratio.rb', line 24

def to_basic_ratio
  Tonal::Ratio.new(antecedent, consequent)
end