class Babosa::Transliterator::Base
Constants
- APPROXIMATIONS
Attributes
approximations[R]
Public Class Methods
new()
click to toggle source
# File lib/babosa/transliterator/base.rb, line 66 def initialize if self.class < Base @approximations = self.class.superclass.instance.approximations.dup else @approximations = {} end self.class.const_get(:APPROXIMATIONS).inject(@approximations) do |memo, object| index = object[0].codepoints.shift value = object[1].codepoints memo[index] = value.length == 1 ? value[0] : value memo end @approximations.freeze end
Public Instance Methods
[](codepoint)
click to toggle source
Accepts a single UTF-8 codepoint and returns the ASCII character code used as the transliteration value.
# File lib/babosa/transliterator/base.rb, line 83 def [](codepoint) @approximations[codepoint] end
transliterate(string)
click to toggle source
Transliterates a string.
# File lib/babosa/transliterator/base.rb, line 88 def transliterate(string) string.codepoints.map { |char| self[char] || char }.flatten.pack("U*") end