Class: HeadMusic::Instruments::PlayingTechnique
- Inherits:
-
Object
- Object
- HeadMusic::Instruments::PlayingTechnique
- Includes:
- Named
- Defined in:
- lib/head_music/instruments/playing_technique.rb
Constant Summary collapse
- RECORDS =
YAML.load_file(File.("playing_techniques.yml", __dir__)).freeze
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#meaning ⇒ Object
readonly
Returns the value of attribute meaning.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
-
#name_key ⇒ Object
readonly
Returns the value of attribute name_key.
-
#notations ⇒ Object
readonly
Returns the value of attribute notations.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object included from Named
- #hash ⇒ Object
- #inferred_name ⇒ Object private
-
#initialize(name_key) ⇒ PlayingTechnique
constructor
private
A new instance of PlayingTechnique.
- #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: HeadMusic::Named::Locale::DEFAULT_CODE) ⇒ Object
- #name=(name) ⇒ Object included from Named
- #to_s ⇒ Object
Constructor Details
#initialize(name_key) ⇒ PlayingTechnique (private)
Returns a new instance of PlayingTechnique.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/head_music/instruments/playing_technique.rb', line 61 def initialize(name_key) @name_key = name_key.to_s record = RECORDS.dig("playing_techniques", @name_key) return unless record @scopes = record["scopes"] @origin = record["origin"] @meaning = record["meaning"] @notations = record["notations"] end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#meaning ⇒ Object (readonly)
Returns the value of attribute meaning.
10 11 12 |
# File 'lib/head_music/instruments/playing_technique.rb', line 10 def meaning @meaning end |
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
#name_key ⇒ Object (readonly)
Returns the value of attribute name_key.
10 11 12 |
# File 'lib/head_music/instruments/playing_technique.rb', line 10 def name_key @name_key end |
#notations ⇒ Object (readonly)
Returns the value of attribute notations.
10 11 12 |
# File 'lib/head_music/instruments/playing_technique.rb', line 10 def notations @notations end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
10 11 12 |
# File 'lib/head_music/instruments/playing_technique.rb', line 10 def origin @origin end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
10 11 12 |
# File 'lib/head_music/instruments/playing_technique.rb', line 10 def scopes @scopes end |
Class Method Details
.all ⇒ Object
21 22 23 |
# File 'lib/head_music/instruments/playing_technique.rb', line 21 def all @all ||= technique_keys.map { |key| get(key) } end |
.for_scope(scope) ⇒ Object
25 26 27 28 |
# File 'lib/head_music/instruments/playing_technique.rb', line 25 def for_scope(scope) scope = scope.to_s all.select { |technique| technique.scopes&.include?(scope) } end |
.get(identifier) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/head_music/instruments/playing_technique.rb', line 13 def get(identifier) return identifier if identifier.is_a?(self) name_key = HeadMusic::Utilities::Case.to_snake_case(identifier) @instances ||= {} @instances[name_key] ||= new(name_key) end |
.technique_keys ⇒ Object (private)
32 33 34 |
# File 'lib/head_music/instruments/playing_technique.rb', line 32 def technique_keys RECORDS["playing_techniques"]&.keys || [] end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
45 46 47 48 49 |
# File 'lib/head_music/instruments/playing_technique.rb', line 45 def ==(other) return false unless other.is_a?(self.class) name_key == other.name_key end |
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#hash ⇒ Object
51 52 53 |
# File 'lib/head_music/instruments/playing_technique.rb', line 51 def hash name_key.hash end |
#inferred_name ⇒ Object (private)
72 73 74 |
# File 'lib/head_music/instruments/playing_technique.rb', line 72 def inferred_name name_key.to_s.tr("_", " ") 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: HeadMusic::Named::Locale::DEFAULT_CODE) ⇒ Object
37 38 39 |
# File 'lib/head_music/instruments/playing_technique.rb', line 37 def name(locale_code: HeadMusic::Named::Locale::DEFAULT_CODE) I18n.translate(name_key, scope: "head_music.playing_techniques", locale: locale_code, default: inferred_name) end |
#name=(name) ⇒ Object Originally defined in module Named
#to_s ⇒ Object
41 42 43 |
# File 'lib/head_music/instruments/playing_technique.rb', line 41 def to_s name end |