Class: TwitterCldr::Transforms::Transliterator

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/transforms/transliterator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, source_locale, target_locale) ⇒ Transliterator

Returns a new instance of Transliterator.



15
16
17
18
19
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 15

def initialize(text, source_locale, target_locale)
  @text = text
  @source_locale = locale_klass.parse(source_locale)
  @target_locale = locale_klass.parse(target_locale).maximize
end

Instance Attribute Details

#source_localeObject (readonly)

Returns the value of attribute source_locale.



13
14
15
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 13

def source_locale
  @source_locale
end

#target_localeObject (readonly)

Returns the value of attribute target_locale.



13
14
15
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 13

def target_locale
  @target_locale
end

#textObject (readonly)

Returns the value of attribute text.



13
14
15
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 13

def text
  @text
end

Class Method Details

.transliterate(text, source_locale, target_locale) ⇒ Object



9
10
11
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 9

def self.transliterate(text, source_locale, target_locale)
  new(text, source_locale, target_locale).transliterate
end

Instance Method Details

#transliterateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twitter_cldr/transforms/transliterator.rb', line 21

def transliterate
  result = text.dup

  each_source_locale do |source_locale|
    transform_id = TransformId.find(source_locale, target_locale)

    if transform_id
      transformer = Transformer.get(transform_id)
      result = transformer.transform(result)
    end
  end

  result
end