Class: HeadMusic::Analysis::DiatonicInterval::Localization

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_nameObject (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_codeObject (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

#keyObject (private)



34
35
36
# File 'lib/head_music/analysis/diatonic_interval/localization.rb', line 34

def key
  HeadMusic::Utilities::HashKey.for(computed_name)
end

#nameObject



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

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

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