Method: Prekladatelj::Latin.to_cyrillic

Defined in:
lib/prekladatelj.rb

.to_cyrillic(line, *args) ⇒ Object

Parameters:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/prekladatelj.rb', line 70

def self.to_cyrillic(line, *args)
  str = String line[0..-1]

  if args.any? :eastern
    line = str.split.to_a
    line.each do |word|
      if word.start_with? "je"
        word["je"] = "е"
      end
      if word.gsub(/\W+/, '') == "se"
        word["se"] = "ся"
      end
      while word =~ /[^aiueoyj](je)/
        word["je"] = "ье"
      end
    end
    str = line.join " "

    EASTERN.each_pair do |k, v|
      str.gsub! k, v
      str.gsub! k.capitalize, v.capitalize
      str.gsub! k.upcase, v.upcase
    end
  end

  UPPER.each { |x| str.gsub! x, Cyrillic::UPPER[UPPER.index(x)] if UPPER.any? x}
  DOWN.each { |x| str.gsub! x, Cyrillic::DOWN[DOWN.index(x)] if DOWN.any? x}

  str
end