Sha256: 6964fea5005951c46e16c51d330c1900c21e206c21e33941c43c4e0689054c4a

Contents?: true

Size: 779 Bytes

Versions: 25

Compression:

Stored size: 779 Bytes

Contents

class HeadMusic::Accidental
  ACCIDENTAL_SEMITONES = {
    '#' => 1,
    '##' => 2,
    'b' => -1,
    'bb' => -2
  }

  attr_reader :string

  def self.get(identifier)
    for_symbol(identifier) || for_interval(identifier)
  end

  def self.for_symbol(identifier)
    @accidentals ||= {}
    @accidentals[identifier.to_s] ||= new(identifier.to_s) if ACCIDENTAL_SEMITONES.keys.include?(identifier.to_s)
  end

  def self.for_interval(semitones)
    @accidentals ||= {}
    @accidentals[semitones.to_i] ||= ACCIDENTAL_SEMITONES.key(semitones.to_i)
  end

  def initialize(string)
    @string = string
  end

  def to_s
    string
  end

  def ==(value)
    to_s == value.to_s
  end

  def semitones
    ACCIDENTAL_SEMITONES.fetch(string, 0)
  end

  private_class_method :new
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
head_music-0.16.2 lib/head_music/accidental.rb
head_music-0.16.0 lib/head_music/accidental.rb
head_music-0.14.8 lib/head_music/accidental.rb
head_music-0.14.7 lib/head_music/accidental.rb
head_music-0.14.5 lib/head_music/accidental.rb
head_music-0.14.4 lib/head_music/accidental.rb
head_music-0.14.2 lib/head_music/accidental.rb
head_music-0.14.1 lib/head_music/accidental.rb
head_music-0.13.2 lib/head_music/accidental.rb
head_music-0.11.9 lib/head_music/accidental.rb
head_music-0.11.8 lib/head_music/accidental.rb
head_music-0.11.7 lib/head_music/accidental.rb
head_music-0.11.6 lib/head_music/accidental.rb
head_music-0.11.5 lib/head_music/accidental.rb
head_music-0.11.4 lib/head_music/accidental.rb
head_music-0.11.3 lib/head_music/accidental.rb
head_music-0.11.2 lib/head_music/accidental.rb
head_music-0.11.1 lib/head_music/accidental.rb
head_music-0.10.0 lib/head_music/accidental.rb
head_music-0.5.2 lib/head_music/accidental.rb