lib/head_music/sign.rb in head_music-0.27.0 vs lib/head_music/sign.rb in head_music-0.28.0
- old
+ new
@@ -1,38 +1,39 @@
# frozen_string_literal: true
-require 'head_music/musical_symbol'
+require "head_music/musical_symbol"
# A Sign is a symbol that modifies pitch, such as a sharp, flat, or natural.
+# In French, sharps and flats in the key signature are called "altérations".
class HeadMusic::Sign
include Comparable
attr_reader :identifier, :cents, :musical_symbols
delegate :ascii, :unicode, :html_entity, to: :musical_symbol
SIGN_RECORDS = [
{
identifier: :sharp, cents: 100,
- symbols: [{ ascii: '#', unicode: '♯', html_entity: '♯' }],
+ symbols: [{ascii: "#", unicode: "♯", html_entity: "♯"}]
},
{
identifier: :flat, cents: -100,
- symbols: [{ ascii: 'b', unicode: '♭', html_entity: '♭' }],
+ symbols: [{ascii: "b", unicode: "♭", html_entity: "♭"}]
},
{
identifier: :natural, cents: 0,
- symbols: [{ ascii: '', unicode: '♮', html_entity: '♮' }],
+ symbols: [{ascii: "", unicode: "♮", html_entity: "♮"}]
},
{
identifier: :double_sharp, cents: 200,
- symbols: [{ ascii: 'x', unicode: '𝄪', html_entity: '𝄪' }],
+ symbols: [{ascii: "x", unicode: "𝄪", html_entity: "𝄪"}]
},
{
identifier: :double_flat, cents: -200,
- symbols: [{ ascii: 'bb', unicode: '𝄫', html_entity: '𝄫' }],
- },
+ symbols: [{ascii: "bb", unicode: "𝄫", html_entity: "𝄫"}]
+ }
].freeze
SIGN_IDENTIFIERS = SIGN_RECORDS.map { |attributes| attributes[:identifier] }.freeze
def self.all
@@ -42,11 +43,11 @@
def self.symbols
@symbols ||= all.map { |sign| [sign.ascii, sign.unicode] }.flatten.reject { |s| s.nil? || s.empty? }
end
def self.matcher
- @matcher ||= Regexp.new symbols.join('|')
+ @matcher ||= Regexp.new symbols.join("|")
end
def self.symbol?(candidate)
candidate =~ /^(#{matcher})$/
end
@@ -64,15 +65,15 @@
sign.send(key) == value if %i[cents semitones].include?(key.to_sym)
end
end
def name
- identifier.to_s.tr('_', ' ')
+ identifier.to_s.tr("_", " ")
end
def representions
- [identifier, identifier.to_s, name, ascii, unicode, html_entity].
- reject { |representation| representation.to_s.strip == '' }
+ [identifier, identifier.to_s, name, ascii, unicode, html_entity]
+ .reject { |representation| representation.to_s.strip == "" }
end
def semitones
cents / 100.0
end