Sha256: 6c7c94aea257e774411ab5136efa4fdf4f65612488a274357e18ee87877a2892

Contents?: true

Size: 832 Bytes

Versions: 6

Compression:

Stored size: 832 Bytes

Contents

class HeadMusic::Meter
  attr_reader :top_number, :bottom_number

  NAMED = {
    common_time: '4/4',
    cut_time: '2/2'
  }

  def self.get(identifier)
    identifer = identifer.to_s
    identifier = NAMED[identifier.to_sym] || identifier
    new(*identifier.split('/').map(&:to_i))
  end

  def initialize(top_number, bottom_number)
    @top_number, @bottom_number = top_number, bottom_number
  end

  def simple?
    !compound?
  end

  def compound?
    top_number > 3 && top_number / 3 == top_number / 3.0
  end

  def duple?
    top_number == 2
  end

  def triple?
    top_number % 3 == 0
  end

  def quadruple?
    top_number == 4
  end

  def beats_per_measure
    compound? ? top_number / 3 : top_number
  end

  def to_s
    [top_number, bottom_number].join('/')
  end

  def ==(other)
    to_s == other.to_s
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
head_music-0.6.4 lib/head_music/meter.rb
head_music-0.6.3 lib/head_music/meter.rb
head_music-0.6.1 lib/head_music/meter.rb
head_music-0.6.0 lib/head_music/meter.rb
head_music-0.5.4 lib/head_music/meter.rb
head_music-0.5.3 lib/head_music/meter.rb