Class: K2J::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/k2j/converter.rb

Overview

K2J Converter

Version:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.convert(str) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/k2j/converter.rb', line 20

def convert(str)
  initialize unless @initialized

  result = ''
  str.size.times do |i|
    ch = str[i]

    special = special_case(str[i - 1], ch, str[i + 1])
    unless special.nil?
      result << special
      next
    end

    col = index_of(K2J::Map::CHO, K2J::Map.cho(ch))
    row = index_of(K2J::Map::JOONG, K2J::Map.joong(ch))
    gana = K2J::Map::HIRAGANA[col * 13 + row]

    result << (gana.nil? ? ch : gana)

    ad = index_of(K2J::Map::JONG, K2J::Map.jong(ch))
    case ad
    when 0
      result << ""
    when 1
      result << ""
    end
  end

  result
end

.initializeObject



12
13
14
15
16
17
18
# File 'lib/k2j/converter.rb', line 12

def initialize
  break_map(K2J::Map::CHO, K2J::Map.method(:cho))
  break_map(K2J::Map::JOONG, K2J::Map.method(:joong))
  break_map(K2J::Map::JONG, K2J::Map.method(:jong))

  @initialized = true
end