Class: String

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

Overview

文字列クラスにちょっとメソッド追加

Instance Method Summary collapse

Instance Method Details

#join_phoneme(delim = ' ') ⇒ Object

「き ゃ き ゅ き ょ」を「きゃ きゅ きょ」に変換。「っ」歌うから残す



28
29
30
# File 'lib/lyrics_japanese.rb', line 28

def join_phoneme(delim = ' ')
  gsub(/#{delim}([ぁぃぅぇぉゃゅょァィゥェォャュョー-])/, '\1')
end

#katakana?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/lyrics_japanese.rb', line 13

def katakana?
  !(self =~ /\p{Katakana}|[ー-]/).nil?
end

#separate_kana(delim = ' ') ⇒ Object

「うたえー」を「う た え ー」に変換。



18
19
20
21
22
23
24
25
# File 'lib/lyrics_japanese.rb', line 18

def separate_kana(delim = ' ')
  tmp = +''
  each_char do |ch|
    tmp << ch
    tmp << delim unless ch.ascii_only?
  end
  tmp.chomp(delim)
end

#to_hiraganaObject



9
10
11
# File 'lib/lyrics_japanese.rb', line 9

def to_hiragana
  tr('ァ-ン', 'ぁ-ん')
end