Class: TranslationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/mo_translation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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



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_keyObject



16
17
18
# File 'lib/mo_translation.rb', line 16

def toplevel_key
  @hash.keys.first
end

#without_topObject



12
13
14
# File 'lib/mo_translation.rb', line 12

def without_top
  @hash[@hash.keys.first]
end