Class: Rails::Pseudoloc::Codec
- Inherits:
-
Object
- Object
- Rails::Pseudoloc::Codec
- Defined in:
- lib/rails/pseudoloc/codec.rb
Overview
Encodes and decodes strings from the pseudolocalized character set.
Class Method Summary collapse
-
.default_table ⇒ Object
Default pseudolocalization table.
Instance Method Summary collapse
-
#encode(text) ⇒ String
Encodes the given text using the translation table.
-
#initialize(table = Codec.default_table) ⇒ Codec
constructor
Constructs a codec for the given translation table.
Constructor Details
#initialize(table = Codec.default_table) ⇒ Codec
Constructs a codec for the given translation table.
46 47 48 |
# File 'lib/rails/pseudoloc/codec.rb', line 46 def initialize(table = Codec.default_table) @table = table end |
Class Method Details
.default_table ⇒ Object
Returns Default pseudolocalization table.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rails/pseudoloc/codec.rb', line 12 def self.default_table { 'a' => 'àáâãäåāăąǻάαад', 'b' => 'þьБъ', 'c' => '¢çćĉċčсς', 'd' => 'ďđ', 'e' => 'èéêëēĕėęěέεеёє℮', 'f' => 'ƒ', 'g' => 'ĝğġģ', 'h' => 'ĥħћђ', 'i' => 'ìíîïĩīĭįίιϊіїΐ', 'j' => 'ĵј', 'k' => 'ķ', 'l' => 'ĺļľŀłℓ', 'm' => 'm', 'n' => 'ήηńņňʼnŋñ', 'o' => 'òóôõöøōŏőοσόо', 'p' => 'þρр', 'r' => 'ŕŗřѓґгř', 's' => 'śŝşѕš', 't' => 'ţť', 'u' => 'µùúûüũūŭůűųΰυϋύ', 'w' => 'ŵωώẁẃẅ', 'x' => 'хж', 'y' => 'ýÿŷўỳу', 'z' => 'źżž' } end |
Instance Method Details
#encode(text) ⇒ String
Encodes the given text using the translation table.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails/pseudoloc/codec.rb', line 54 def encode(text) output = '' text.each_char.each_with_index do |char, i| alts = @table.fetch(char, [char]) output << alts[i % alts.length] end output end |