Module: HeadMusic::Named
- Included in:
- Clef, Instrument, InstrumentFamily, ReferencePitch, RhythmicUnit, 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.
66 67 68 |
# File 'lib/head_music/named.rb', line 66 def alias_name_keys @alias_name_keys end |
#name_key ⇒ Object (readonly)
Returns the value of attribute name_key.
66 67 68 |
# File 'lib/head_music/named.rb', line 66 def name_key @name_key end |
Class Method Details
.included(base) ⇒ Object
62 63 64 |
# File 'lib/head_music/named.rb', line 62 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
84 85 86 87 88 |
# File 'lib/head_music/named.rb', line 84 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
76 77 78 79 80 81 82 |
# File 'lib/head_music/named.rb', line 76 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.
91 92 93 |
# File 'lib/head_music/named.rb', line 91 def localized_names @localized_names ||= [] end |
#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
72 73 74 |
# File 'lib/head_music/named.rb', line 72 def name(locale_code: Locale::DEFAULT_CODE) localized_name(locale_code: locale_code)&.name end |
#name=(name) ⇒ Object
68 69 70 |
# File 'lib/head_music/named.rb', line 68 def name=(name) ensure_localized_name(name: name) end |