Class: ReadingKanjiInKana::Kanji
- Inherits:
-
Object
- Object
- ReadingKanjiInKana::Kanji
- Defined in:
- lib/reading_kanji_in_kana.rb
Instance Attribute Summary collapse
-
#opt ⇒ Object
Returns the value of attribute opt.
Instance Method Summary collapse
-
#initialize(option = nil) ⇒ Kanji
constructor
A new instance of Kanji.
- #to_yomi(kanji = nil) ⇒ Object
Constructor Details
#initialize(option = nil) ⇒ Kanji
Returns a new instance of Kanji.
9 10 11 |
# File 'lib/reading_kanji_in_kana.rb', line 9 def initialize(option=nil) @opt = option.dup unless option == nil end |
Instance Attribute Details
#opt ⇒ Object
Returns the value of attribute opt.
7 8 9 |
# File 'lib/reading_kanji_in_kana.rb', line 7 def opt @opt end |
Instance Method Details
#to_yomi(kanji = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/reading_kanji_in_kana.rb', line 13 def to_yomi(kanji=nil) if kanji == nil p 'ReadingKanjiInKana::Kanji::kanji_to_yomi error: the input string is null. please input `kanji` string.' return nil end text = kanji.dup if opt == nil nm = Natto::MeCab.new else nm = Natto::MeCab.new(opt) end str_ary = [] nm.parse(text) do |n| str = n.feature.split(',')[7] str_ary.push("#{str}") unless str.match(/\*/) end str_ary.uniq! yomi = str_ary.join(',') yomi end |