Class: HeadMusic::Rudiment::Solmization
- Includes:
- Named
- Defined in:
- lib/head_music/rudiment/solmization.rb
Overview
A solmization is the rendering of scale degrees as syllables.
Constant Summary collapse
- DEFAULT_SOLMIZATION =
"solfège"- RECORDS =
YAML.load_file(File.("solmizations.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
-
#syllables ⇒ Object
readonly
Returns the value of attribute syllables.
Class Method Summary collapse
Instance Method Summary collapse
- #ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object included from Named
-
#initialize(name = nil) ⇒ Solmization
constructor
private
A new instance of Solmization.
- #initialize_data_from_record(record) ⇒ Object private
- #load_translation_aliases ⇒ Object private
- #localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object included from Named
- #localized_name_in_default_locale ⇒ Object included from Named private
- #localized_name_in_locale_matching_language(locale) ⇒ Object included from Named private
- #localized_name_in_matching_locale(locale) ⇒ Object included from Named private
-
#localized_names ⇒ Object
included
from Named
Returns an array of LocalizedName instances that are synonymous with the name.
- #name(locale_code: Locale::DEFAULT_CODE) ⇒ Object included from Named
- #name=(name) ⇒ Object included from Named
- #record_for_name(name) ⇒ Object private
- #translation_aliases ⇒ Object private
Constructor Details
#initialize(name = nil) ⇒ Solmization (private)
Returns a new instance of Solmization.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/head_music/rudiment/solmization.rb', line 22 def initialize(name = nil) name = nil if name.empty? name ||= DEFAULT_SOLMIZATION record = record_for_name(name) if record initialize_data_from_record(record) else self.name = name end end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
#syllables ⇒ Object (readonly)
Returns the value of attribute syllables.
12 13 14 |
# File 'lib/head_music/rudiment/solmization.rb', line 12 def syllables @syllables end |
Class Method Details
.get(identifier = nil) ⇒ Object
14 15 16 |
# File 'lib/head_music/rudiment/solmization.rb', line 14 def self.get(identifier = nil) get_by_name(identifier) end |
Instance Method Details
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#initialize_data_from_record(record) ⇒ Object (private)
42 43 44 45 |
# File 'lib/head_music/rudiment/solmization.rb', line 42 def initialize_data_from_record(record) self.name = record[:name] @syllables = record[:syllables] end |
#load_translation_aliases ⇒ Object (private)
51 52 53 54 55 56 57 58 |
# File 'lib/head_music/rudiment/solmization.rb', line 51 def load_translation_aliases aliases = [] I18n.config.available_locales.each do |locale| translation = I18n.translate("head_music.rudiments.solfege", locale: locale, default: nil) aliases << translation if translation && translation != "solfege" end aliases.compact.uniq end |
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#localized_name_in_default_locale ⇒ Object (private) Originally defined in module Named
#localized_name_in_locale_matching_language(locale) ⇒ Object (private) Originally defined in module Named
#localized_name_in_matching_locale(locale) ⇒ Object (private) Originally defined in module Named
#localized_names ⇒ Object Originally defined in module Named
Returns an array of LocalizedName instances that are synonymous with the name.
#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#name=(name) ⇒ Object Originally defined in module Named
#record_for_name(name) ⇒ Object (private)
33 34 35 36 37 38 39 40 |
# File 'lib/head_music/rudiment/solmization.rb', line 33 def record_for_name(name) key = HeadMusic::Utilities::HashKey.for(name) RECORDS.detect do |record| name_strings = [record[:name]] + (record[:aliases] || []) + translation_aliases name_keys = name_strings.map { |name_string| HeadMusic::Utilities::HashKey.for(name_string) } name_keys.include?(key) end end |
#translation_aliases ⇒ Object (private)
47 48 49 |
# File 'lib/head_music/rudiment/solmization.rb', line 47 def translation_aliases @translation_aliases ||= load_translation_aliases end |