Class: Mext::Music::Meter
- Inherits:
-
Object
- Object
- Mext::Music::Meter
- 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
-
#divisor ⇒ Object
(also: #denominator)
Returns the value of attribute divisor.
-
#numerator ⇒ Object
Returns the value of attribute numerator.
Instance Method Summary collapse
-
#initialize(n, d) ⇒ Meter
constructor
A new instance of Meter.
- #to_r ⇒ Object
- #to_s ⇒ Object
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
#divisor ⇒ Object 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 |
#numerator ⇒ Object
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_r ⇒ Object
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_s ⇒ Object
27 28 29 |
# File 'lib/mext/music/meter.rb', line 27 def to_s "#{self.numerator}/#{self.divisor}" end |