Class: KanjiMaster::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/kanji_master/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Converter

Returns a new instance of Converter.



6
7
8
# File 'lib/kanji_master/converter.rb', line 6

def initialize(api_key: nil)
  @api_key = api_key
end

Instance Method Details

#hira(text) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/kanji_master/converter.rb', line 22

def hira(text)
  if text.match(RegexConstant::HIRAGANA_REGEX)
    text
  elsif text.match(RegexConstant::KATAKANA_REGEX)
    NKF.nkf("--hiragana -Ww", text)
  elsif text.match(RegexConstant::ROMAJI_REGEX)
    Romaji.romaji2kana text, :kana_type => :hiragana
  end
end

#hiragana(text) ⇒ Object



21
# File 'lib/kanji_master/converter.rb', line 21

def hiragana(text); hira(text) end

#kana(text) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/kanji_master/converter.rb', line 11

def kana(text)
  if text.match(RegexConstant::HIRAGANA_REGEX)
    NKF.nkf("--katakana -Ww", text)
  elsif text.match(RegexConstant::KATAKANA_REGEX)
    text
  elsif text.match(RegexConstant::ROMAJI_REGEX)
    Romaji.romaji2kana text
  end
end

#katakana(text) ⇒ Object



10
# File 'lib/kanji_master/converter.rb', line 10

def katakana(text); kana(text) end