Class: HeadMusic::Instruments::PlayingTechnique

Inherits:
Object
  • Object
show all
Includes:
Named
Defined in:
lib/head_music/instruments/playing_technique.rb

Constant Summary collapse

RECORDS =
YAML.load_file(File.expand_path("playing_techniques.yml", __dir__)).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_keysObject (readonly) Originally defined in module Named

Returns the value of attribute alias_name_keys.

#meaningObject (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_keyObject (readonly) Originally defined in module Named

Returns the value of attribute name_key.

#name_keyObject (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

#notationsObject (readonly)

Returns the value of attribute notations.



10
11
12
# File 'lib/head_music/instruments/playing_technique.rb', line 10

def notations
  @notations
end

#originObject (readonly)

Returns the value of attribute origin.



10
11
12
# File 'lib/head_music/instruments/playing_technique.rb', line 10

def origin
  @origin
end

#scopesObject (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

.allObject



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_keysObject (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

#hashObject



51
52
53
# File 'lib/head_music/instruments/playing_technique.rb', line 51

def hash
  name_key.hash
end

#inferred_nameObject (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_localeObject (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_namesObject 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_sObject



41
42
43
# File 'lib/head_music/instruments/playing_technique.rb', line 41

def to_s
  name
end