Class: Mext::Music::Meter

Inherits:
Object
  • Object
show all
Defined in:
lib/mext/music/meter.rb

Overview

Meter:

in music we cannot use the Rational class because the latter will make all due conversions simplifying meters (like: 4/4 => 1/1), which is not what we want

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n, d) ⇒ Meter

Returns a new instance of Meter.



17
18
19
20
# File 'lib/mext/music/meter.rb', line 17

def initialize(n, d)
  self.numerator = n.to_f
  self.divisor   = d.to_f
end

Instance Attribute Details

#divisorObject Also known as: denominator

Returns the value of attribute divisor.



13
14
15
# File 'lib/mext/music/meter.rb', line 13

def divisor
  @divisor
end

#numeratorObject

Returns the value of attribute numerator.



13
14
15
# File 'lib/mext/music/meter.rb', line 13

def numerator
  @numerator
end

Instance Method Details

#to_rObject

Raises:

  • (ZeroDivisionError)


22
23
24
25
# File 'lib/mext/music/meter.rb', line 22

def to_r
  raise ZeroDivisionError, "#{self.numerator}/#{self.divisor} provokes a zero-division error" unless self.divisor != 0
  Rational(self.numerator, self.divisor)
end

#to_sObject



27
28
29
# File 'lib/mext/music/meter.rb', line 27

def to_s
  "#{self.numerator}/#{self.divisor}"
end