Module: HeadMusic::Named
- Included in:
- Instruments::Instrument, Instruments::InstrumentFamily, Rudiment::ChromaticInterval, Rudiment::Clef, Rudiment::ReferencePitch, Rudiment::RhythmicUnit, Rudiment::Solmization
- Defined in:
- lib/head_music/named.rb
Overview
NameRudiment is a module to be included in classes whose instances may be identified by name.
Defined Under Namespace
Modules: ClassMethods Classes: Locale, LocalizedName
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
readonly
Returns the value of attribute alias_name_keys.
-
#name_key ⇒ Object
readonly
Returns the value of attribute name_key.
Class Method Summary collapse
Instance Method Summary collapse
- #ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
- #localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
-
#localized_names ⇒ Object
Returns an array of LocalizedName instances that are synonymous with the name.
- #name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
- #name=(name) ⇒ Object
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly)
Returns the value of attribute alias_name_keys.
64 65 66 |
# File 'lib/head_music/named.rb', line 64 def alias_name_keys @alias_name_keys end |
#name_key ⇒ Object (readonly)
Returns the value of attribute name_key.
64 65 66 |
# File 'lib/head_music/named.rb', line 64 def name_key @name_key end |
Class Method Details
.included(base) ⇒ Object
60 61 62 |
# File 'lib/head_music/named.rb', line 60 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
82 83 84 85 86 |
# File 'lib/head_music/named.rb', line 82 def ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) @localized_names ||= [] @localized_names << LocalizedName.new(name: name, locale_code: locale_code, abbreviation: abbreviation) @localized_names.uniq! end |
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/head_music/named.rb', line 74 def localized_name(locale_code: Locale::DEFAULT_CODE) locale = Locale.get(locale_code || Locale::DEFAULT_CODE) localized_name_in_matching_locale(locale) || localized_name_in_locale_matching_language(locale) || localized_name_in_default_locale || localized_names.first end |
#localized_names ⇒ Object
Returns an array of LocalizedName instances that are synonymous with the name.
89 90 91 |
# File 'lib/head_music/named.rb', line 89 def localized_names @localized_names ||= [] end |
#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
70 71 72 |
# File 'lib/head_music/named.rb', line 70 def name(locale_code: Locale::DEFAULT_CODE) localized_name(locale_code: locale_code)&.name end |
#name=(name) ⇒ Object
66 67 68 |
# File 'lib/head_music/named.rb', line 66 def name=(name) ensure_localized_name(name: name) end |