Class: Ununiga::JosaPicker

Inherits:
Object
  • Object
show all
Defined in:
lib/ununiga/josa_picker.rb

Overview

한글 조사 변경 클래스

Constant Summary collapse

JOSAS =
[%w( ),
 %w( ),
 %w( ),
 %w( ),
 %w(으로 ),
 %w(이의 )
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ JosaPicker

Returns a new instance of JosaPicker.



22
23
24
# File 'lib/ununiga/josa_picker.rb', line 22

def initialize(str)
  @korean_str = str
end

Instance Attribute Details

#korean_strObject (readonly)

Returns the value of attribute korean_str.



14
15
16
# File 'lib/ununiga/josa_picker.rb', line 14

def korean_str
  @korean_str
end

Class Method Details

.takewell(str) ⇒ Object



17
18
19
# File 'lib/ununiga/josa_picker.rb', line 17

def takewell(str)
  new(str).takewell
end

Instance Method Details

#josasObject



39
40
41
42
43
44
45
# File 'lib/ununiga/josa_picker.rb', line 39

def josas
  res = []
  korean_str.scan josa_regexp do |matched|
    res << [$~.offset(0)[0], JOSAS.find { |josa| josa.include? matched[0] }]
  end
  res
end

#takewellObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ununiga/josa_picker.rb', line 26

def takewell
  korean_str.gsub josa_regexp do |matched|
    index = $~.offset(0)[0]
    if index == 0
      matched
    else
      josa = JOSAS.find { |jo| josa_convension(jo).include? matched }
      splitter = JasoSplitter.new(korean_str[index - 1])
      josa[(splitter.jongsung ? 0 : 1)]
    end
  end
end