Class: Chronic18n::Translator
- Inherits:
-
Object
- Object
- Chronic18n::Translator
- Defined in:
- lib/chronic18n/translator.rb
Instance Method Summary collapse
-
#initialize(txt, lang) ⇒ Translator
constructor
A new instance of Translator.
- #work ⇒ Object
Constructor Details
#initialize(txt, lang) ⇒ Translator
Returns a new instance of Translator.
9 10 11 |
# File 'lib/chronic18n/translator.rb', line 9 def initialize(txt, lang) @txt, @lang = txt, lang.to_s end |
Instance Method Details
#work ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chronic18n/translator.rb', line 13 def work # Return the text if we don't have the dictionary return @txt unless dic = DICS[@lang] # Regex gsub! if rxp = DICS["#{@lang}_regex"] rxp.each { |k, v| @txt.gsub!(k, v)} end # Match translate @txt.split(/\s/).map { |w| dic[w] || w }.join(" ") end |