Class: Ununiga::JosaPicker
- Inherits:
-
Object
- Object
- Ununiga::JosaPicker
- Defined in:
- lib/ununiga/josa_picker.rb
Overview
한글 조사 변경 클래스
Constant Summary collapse
- JOSAS =
[%w(은 는), %w(이 가), %w(을 를), %w(과 와), %w(으로 로), %w(이의 의) ].freeze
Instance Attribute Summary collapse
-
#korean_str ⇒ Object
readonly
Returns the value of attribute korean_str.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(str) ⇒ JosaPicker
constructor
A new instance of JosaPicker.
- #josas ⇒ Object
- #takewell ⇒ Object
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_str ⇒ Object (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
#josas ⇒ Object
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 |
#takewell ⇒ Object
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 |