class HeadMusic::Sign
A Sign
is a symbol that modifies pitch, such as a sharp, flat, or natural.
Constants
- SIGN_IDENTIFIERS
- SIGN_RECORDS
Attributes
cents[R]
identifier[R]
musical_symbols[R]
Public Class Methods
all()
click to toggle source
# File lib/head_music/sign.rb, line 38 def self.all SIGN_RECORDS.map { |attributes| new(attributes) } end
by(key, value)
click to toggle source
# File lib/head_music/sign.rb, line 62 def self.by(key, value) all.detect do |sign| sign.send(key) == value if %i[cents semitones].include?(key.to_sym) end end
get(identifier)
click to toggle source
# File lib/head_music/sign.rb, line 54 def self.get(identifier) return identifier if identifier.is_a?(HeadMusic::Sign) all.detect do |sign| sign.representions.include?(identifier) end end
matcher()
click to toggle source
# File lib/head_music/sign.rb, line 46 def self.matcher @matcher ||= Regexp.new symbols.join('|') end
symbol?(candidate)
click to toggle source
# File lib/head_music/sign.rb, line 50 def self.symbol?(candidate) candidate =~ /^(#{matcher})$/ end
symbols()
click to toggle source
# File lib/head_music/sign.rb, line 42 def self.symbols @symbols ||= all.map { |sign| [sign.ascii, sign.unicode] }.flatten.reject { |s| s.nil? || s.empty? } end
Private Class Methods
new(attributes)
click to toggle source
# File lib/head_music/sign.rb, line 100 def initialize(attributes) @identifier = attributes[:identifier] @cents = attributes[:cents] initialize_musical_symbols(attributes[:symbols]) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/head_music/sign.rb, line 89 def <=>(other) other = HeadMusic::Sign.get(other) cents <=> other.cents end
musical_symbol()
click to toggle source
# File lib/head_music/sign.rb, line 94 def musical_symbol musical_symbols.first end
name()
click to toggle source
# File lib/head_music/sign.rb, line 68 def name identifier.to_s.tr('_', ' ') end
representions()
click to toggle source
# File lib/head_music/sign.rb, line 72 def representions [identifier, identifier.to_s, name, ascii, unicode, html_entity]. reject { |representation| representation.to_s.strip == '' } end
semitones()
click to toggle source
# File lib/head_music/sign.rb, line 77 def semitones cents / 100.0 end
to_s()
click to toggle source
# File lib/head_music/sign.rb, line 85 def to_s unicode end
Private Instance Methods
initialize_musical_symbols(list)
click to toggle source
# File lib/head_music/sign.rb, line 106 def initialize_musical_symbols(list) @musical_symbols = (list || []).map do |record| HeadMusic::MusicalSymbol.new( unicode: record[:unicode], ascii: record[:ascii], html_entity: record[:html_entity] ) end end