Sha256: 0cbb013b3f9833b68f74f1905a1ecd382d486ce1293b34ce97d38ece85cdaf96

Contents?: true

Size: 563 Bytes

Versions: 5

Compression:

Stored size: 563 Bytes

Contents

# frozen_string_literal: true

# Consonance is a description of intervals that sound more pleasing.
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

5 entries across 5 versions & 1 rubygems

Version Path
head_music-0.20.0 lib/head_music/consonance.rb
head_music-0.19.2 lib/head_music/consonance.rb
head_music-0.19.1 lib/head_music/consonance.rb
head_music-0.19.0 lib/head_music/consonance.rb
head_music-0.18.0 lib/head_music/consonance.rb