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(으로 )
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ JosaPicker

Returns a new instance of JosaPicker.



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

def initialize(str)
  @korean_str = str
end

Instance Attribute Details

#korean_strObject (readonly)

Returns the value of attribute korean_str.



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

def korean_str
  @korean_str
end

Class Method Details

.takewell(str) ⇒ Object



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

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

Instance Method Details

#josasObject



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

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



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

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