Class: HeadMusic::Analysis::DiatonicInterval::Localization
- Inherits:
-
Object
- Object
- HeadMusic::Analysis::DiatonicInterval::Localization
- Defined in:
- lib/head_music/analysis/diatonic_interval/localization.rb
Overview
An interval names itself from its number and its quality rather than from a fixed vocabulary, so its translation has to be looked up by the name it computed rather than registered against it ahead of time. Anything missing along the way – no locale asked for, no translations loaded, no entry under either heading – leaves the computed name standing.
Instance Attribute Summary collapse
-
#computed_name ⇒ Object
readonly
Returns the value of attribute computed_name.
-
#locale_code ⇒ Object
readonly
Returns the value of attribute locale_code.
Instance Method Summary collapse
-
#initialize(computed_name, locale_code) ⇒ Localization
constructor
A new instance of Localization.
-
#key ⇒ Object
private
-
#name ⇒ Object
-
#table ⇒ Object
private
-
#translated ⇒ Object
private
Constructor Details
#initialize(computed_name, locale_code) ⇒ Localization
Returns a new instance of Localization.
10 11 12 13 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 10 def initialize(computed_name, locale_code) @computed_name = computed_name @locale_code = locale_code end |
Instance Attribute Details
#computed_name ⇒ Object (readonly)
Returns the value of attribute computed_name.
8 9 10 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 8 def computed_name @computed_name end |
#locale_code ⇒ Object (readonly)
Returns the value of attribute locale_code.
8 9 10 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 8 def locale_code @locale_code end |
Instance Method Details
#key ⇒ Object (private)
34 35 36 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 34 def key HeadMusic::Utilities::HashKey.for(computed_name) end |
#name ⇒ Object
15 16 17 18 19 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 15 def name return computed_name unless locale_code translated || computed_name end |
#table ⇒ Object (private)
29 30 31 32 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 29 def table translations = I18n.backend.translations[locale_code] translations && translations[:head_music] end |
#translated ⇒ Object (private)
23 24 25 26 27 |
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 23 def translated return unless table table.dig(:diatonic_intervals, key) || table.dig(:chromatic_intervals, key) end |