Class: Mext::Numeric::Meter

Inherits:
Object
  • Object
show all
Defined in:
lib/mext/numeric/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/numeric/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/numeric/meter.rb', line 13

def divisor
  @divisor
end

#numeratorObject

Returns the value of attribute numerator.



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

def numerator
  @numerator
end

Instance Method Details

#to_rObject



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

def to_r
  Rational(self.numerator, self.divisor)
end

#to_sObject



26
27
28
# File 'lib/mext/numeric/meter.rb', line 26

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