Sha256: 7133ec1b047b6b68c9555aba3a5459f3d7adaf03c50795843857524fc026d3d2

Contents?: true

Size: 575 Bytes

Versions: 6

Compression:

Stored size: 575 Bytes

Contents

# Consonance describes a category or degree of harmonic pleasantness: perfect, imperfect, or dissonant
class HeadMusic::Consonance
  LEVELS = %w[perfect imperfect dissonant].freeze

  def self.get(name)
    @consonances ||= {}
    @consonances[name.to_sym] ||= new(name) if LEVELS.include?(name.to_s)
  end

  attr_reader :name

  delegate :to_s, :to_sym, to: :name

  def initialize(name)
    @name = name.to_s.to_sym
  end

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

  LEVELS.each do |method_name|
    define_method(:"#{method_name}?") { to_s == method_name }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
head_music-7.0.5 lib/head_music/consonance.rb
head_music-7.0.4 lib/head_music/consonance.rb
head_music-7.0.3 lib/head_music/consonance.rb
head_music-7.0.2 lib/head_music/consonance.rb
head_music-7.0.1 lib/head_music/consonance.rb
head_music-7.0.0 lib/head_music/consonance.rb