Sha256: ca693034fb9a9015721b40f4394ef49ecafaf6f6bd4e403f142c4925dfd0d08b

Contents?: true

Size: 597 Bytes

Versions: 27

Compression:

Stored size: 597 Bytes

Contents

# frozen_string_literal: true

# 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: :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

27 entries across 27 versions & 1 rubygems

Version Path
head_music-0.24.0 lib/head_music/consonance.rb
head_music-0.23.4 lib/head_music/consonance.rb
head_music-0.23.3 lib/head_music/consonance.rb
head_music-0.23.2 lib/head_music/consonance.rb
head_music-0.23.1 lib/head_music/consonance.rb
head_music-0.23.0 lib/head_music/consonance.rb
head_music-0.22.0 lib/head_music/consonance.rb