Class: ReadyForI18N::KeyMapper

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

Instance Method Summary collapse

Constructor Details

#initialize(text1, text2) ⇒ KeyMapper

Returns a new instance of KeyMapper.



3
4
5
6
7
8
9
# File 'lib/key_mapper.rb', line 3

def initialize(text1,text2)
  @hash = {}
  arr1 = text1.split("\n")
  arr2 = text2.split("\n")
  raise 'Mapper files should contain the same number of lines' if arr1.size != arr2.size
  arr1.each_with_index { |text,i| @hash[text] = arr2[i] }
end

Instance Method Details

#key_for(text) ⇒ Object



10
11
12
13
# File 'lib/key_mapper.rb', line 10

def key_for(text)
  possible_key = @hash[text] ? @hash[text] : @hash.invert[text]
  possible_key.scan(/\w+/).join('_').downcase
end