class Panayo::Converter
Constants
- DAKUON
濁音
- DAKUTEN
濁点
- HANDAKUON
半濁音
- HANDAKUTEN
半濁点
- HENKAN_TABLE
変換
- KANA
片仮名
Public Class Methods
kana?(char)
click to toggle source
# File lib/panayo/converter.rb, line 48 def kana?(char) KANA.include?(char) end
remove_dakuten(text)
click to toggle source
# File lib/panayo/converter.rb, line 26 def remove_dakuten(text) result = text.gsub(/[#{DAKUON}]/, HENKAN_TABLE) (result.codepoints - DAKUTEN).pack("U*") end
remove_handakuten(text)
click to toggle source
# File lib/panayo/converter.rb, line 31 def remove_handakuten(text) result = text.gsub(/[#{HANDAKUON}]/, HENKAN_TABLE) (result.codepoints - HANDAKUTEN).pack("U*") end
to_hanayo(text)
click to toggle source
# File lib/panayo/converter.rb, line 44 def to_hanayo(text) text.each_char.map{ |char| kana?(char) ? "#{char}゛" : char }.join end
to_kana(text)
click to toggle source
# File lib/panayo/converter.rb, line 36 def to_kana(text) to_zen_kana(text.tr('ぁ-ん', 'ァ-ン')) end
to_zen_kana(text)
click to toggle source
# File lib/panayo/converter.rb, line 40 def to_zen_kana(text) NKF.nkf('-w -X', text) end