Class: Ja::SoundIndex
- Inherits:
-
Object
- Object
- Ja::SoundIndex
- Defined in:
- lib/ja/sound_index.rb
Constant Summary collapse
- VOWEL =
%w[A I U E O]
- CONSONANT =
%w[A K S T N H M Y R W G Z D B P]
- LARGE =
[ 'ア', 'イ', 'ウ', 'エ', 'オ', 'カ', 'キ', 'ク', 'ケ', 'コ', 'サ', 'シ', 'ス', 'セ', 'ソ', 'タ', 'チ', 'ツ', 'テ', 'ト', 'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 'マ', 'ミ', 'ム', 'メ', 'モ', 'ヤ', nil, 'ユ', nil, 'ヨ', 'ラ', 'リ', 'ル', 'レ', 'ロ', 'ワ', 'ヰ', 'ヴ', 'ヱ', 'ヲ', 'ガ', 'ギ', 'グ', 'ゲ', 'ゴ', 'ザ', 'ジ', 'ズ', 'ゼ', 'ゾ', 'ダ', 'ヂ', 'ヅ', 'デ', 'ド', 'バ', 'ビ', 'ブ', 'ベ', 'ボ', 'パ', 'ピ', 'プ', 'ペ', 'ポ', ]
- SMALL =
[ 'ァ', 'ィ', 'ゥ', 'ェ', 'ォ', 'ャ', nil, 'ュ', nil, 'ョ', 'ヮ' ]
- SPECIAL =
{'ッ' => '.', 'ー' => '-', 'ン' => 'N'}
Instance Method Summary collapse
- #consonant(text, with = []) ⇒ Object
-
#initialize(mode) ⇒ SoundIndex
constructor
A new instance of SoundIndex.
- #only_katakana?(text) ⇒ Boolean
- #vowel(text, with = []) ⇒ Object
Constructor Details
#initialize(mode) ⇒ SoundIndex
Returns a new instance of SoundIndex.
22 23 24 |
# File 'lib/ja/sound_index.rb', line 22 def initialize(mode) @mode = mode end |
Instance Method Details
#consonant(text, with = []) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ja/sound_index.rb', line 42 def consonant(text, with=[]) if !only_katakana?(text) raise ArgumentError, 'Error: first param must consist only of katakana.' end text = text.gsub(/([#{LARGE.join}])/u) { i = LARGE.index($1) - LARGE.index($1) % 5 @mode == :ascii ? CONSONANT[i / 5] : LARGE[i] } text = text.gsub(/[#{SMALL.join}]/u, '') special(text, with) end |
#only_katakana?(text) ⇒ Boolean
26 27 28 |
# File 'lib/ja/sound_index.rb', line 26 def only_katakana?(text) text.match /^[#{LARGE.join}#{SMALL.join}#{SPECIAL.keys.join}]+$/u end |
#vowel(text, with = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ja/sound_index.rb', line 30 def vowel(text, with=[]) if !only_katakana?(text) raise ArgumentError, 'Error: first param must consist only of katakana.' end text = text.gsub(/([#{LARGE.join}])([#{SMALL.join}])*/u) { map, snd = $2 ? [SMALL, $2] : [LARGE, $1] arr = @mode == :ascii ? VOWEL : LARGE arr[map.index(snd) % 5] } special(text, with) end |