Class: TranslationFile
- Inherits:
-
Object
- Object
- TranslationFile
- Defined in:
- lib/mo_translation.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #flat_translation_keys ⇒ Object
- #full_key(key) ⇒ Object
-
#initialize(path) ⇒ TranslationFile
constructor
A new instance of TranslationFile.
- #toplevel_key ⇒ Object
- #without_top ⇒ Object
Constructor Details
#initialize(path) ⇒ TranslationFile
Returns a new instance of TranslationFile.
6 7 8 9 10 |
# File 'lib/mo_translation.rb', line 6 def initialize(path) @path = path @hash = YAML.load_file(path) raise %{Expecting exactly one toplevel key (e.g. "en:" or "pl:")} unless @hash.keys.size == 1 end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/mo_translation.rb', line 5 def path @path end |
Instance Method Details
#flat_translation_keys ⇒ Object
20 21 22 |
# File 'lib/mo_translation.rb', line 20 def flat_translation_keys flatten_out_keys(without_top) end |
#full_key(key) ⇒ Object
24 25 26 |
# File 'lib/mo_translation.rb', line 24 def full_key(key) [toplevel_key, key].join(".") end |
#toplevel_key ⇒ Object
16 17 18 |
# File 'lib/mo_translation.rb', line 16 def toplevel_key @hash.keys.first end |
#without_top ⇒ Object
12 13 14 |
# File 'lib/mo_translation.rb', line 12 def without_top @hash[@hash.keys.first] end |