class Tagabaybay::Transliterator

Public Class Methods

process(text) click to toggle source
# File lib/tagabaybay.rb, line 116
def self.process(text)
  tagabaybay = Transliterator.new
  tagabaybay.process(text)
end

Public Instance Methods

process(text) click to toggle source
# File lib/tagabaybay.rb, line 121
def process(text)
  to_translate = text.dup.downcase
  translated   = ""

  while to_translate.length > 0
   match, converted = find_match(to_translate)
   translated += converted
   to_translate.sub!(match, "")
  end

  translated
end

Private Instance Methods

find_match(text) click to toggle source
# File lib/tagabaybay.rb, line 136
def find_match(text)
  matched = Mapping::ALL.find do |matcher, _baybayin|
    Regexp.new("^#{matcher}") =~ text
  end
  matched || [text[0], text[0]]
end