Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions lib/romanize.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,112 @@
module Romanize
def romanize(s)

dictionary = Hash.new
dictionary = {
'あ' => 'a',
'い' => 'i',
'う' => 'u',
'え' => 'e',
'お' => 'o',
'か' => 'ka',
'き' => 'ki',
'く' => 'ku',
'け' => 'ke',
'こ' => 'ko',
'さ' => 'sa',
'し' => 'si',
'す' => 'su',
'せ' => 'se',
'そ' => 'so',
'た' => 'ta',
'ち' => 'ti',
'つ' => 'tu',
'て' => 'te',
'と' => 'to',
'な' => 'na',
'に' => 'ni',
'ぬ' => 'nu',
'ね' => 'ne',
'の' => 'no',
'は' => 'ha',
'ひ' => 'hi',
'ふ' => 'hu',
'へ' => 'he',
'ほ' => 'ho',
'ま' => 'ma',
'み' => 'mi',
'む' => 'mu',
'め' => 'me',
'も' => 'mo',
'や' => 'ya',
'ゆ' => 'yu',
'よ' => 'yo',
'ら' => 'ra',
'り' => 'ri',
'る' => 'ru',
'れ' => 're',
'ろ' => 'ro',
'わ' => 'wa',
'ゐ' => 'wi',
'ゑ' => 'we',
'を' => 'wo',
'ん' => 'n',
'が' => 'ga',
'ぎ' => 'gi',
'ぐ' => 'gu',
'げ' => 'ge',
'ご' => 'go',
'ざ' => 'za',
'じ' => 'zi',
'ず' => 'zu',
'ぜ' => 'ze',
'ぞ' => 'zo',
'だ' => 'da',
'ぢ' => 'di',
'づ' => 'du',
'で' => 'de',
'ど' => 'do',
'ば' => 'ba',
'び' => 'bi',
'ぶ' => 'bu',
'べ' => 'be',
'ぼ' => 'bo',
'ぱ' => 'pa',
'ぴ' => 'pi',
'ぷ' => 'pu',
'ぺ' => 'pe',
'ぽ' => 'po',
'きゃ'=> 'kya', 'きゅ'=> 'kyu', 'きょ'=> 'kyo',
'しゃ'=> 'sya', 'しゅ'=> 'syu', 'しょ'=> 'syo',
'ちゃ'=> 'tya', 'ちゅ'=> 'tyu', 'ちょ'=> 'tyo',
'にゃ'=> 'nya', 'にゅ'=> 'nyu', 'にょ'=> 'nyo',
'ひゃ'=> 'hya', 'ひゅ'=> 'hyu', 'ひょ'=> 'hyo',
'みゃ'=> 'mya', 'みゅ'=> 'myu', 'みょ'=> 'myo',
'りゃ'=> 'rya', 'りゅ'=> 'ryu', 'りょ'=> 'ryo',
'ぎゃ'=> 'gya', 'ぎゅ'=> 'gyu', 'ぎょ'=> 'gyo',
'じゃ'=> 'zya', 'じゅ'=> 'zyu', 'じょ'=> 'zyo',
'ぢゃ'=> 'dya', 'ぢゅ'=> 'dyu', 'ぢょ'=> 'dyo',
'びゃ'=> 'bya', 'びゅ'=> 'byu', 'びょ'=> 'byo',
'ぴゃ'=> 'pya', 'ぴゅ'=> 'pyu', 'ぴょ'=> 'pyo'
}

small_letters = %w(ゃ ゅ ょ ぁ ぃ ぅ)

answer = ""
s.each_char.to_a.each_index do |index|
#next_letter = s[index+1]
#if next_letter
letter = s[index]
answer << dictionary[letter]
end
return answer

# if s == 'ひらがな'
# return 'hiragana'
# elsif s == 'しんじゅく'
# return 'sinzyuku'
# elsif s == 'なっとう'
# return 'nattou'
# end
end
end
28 changes: 28 additions & 0 deletions spec/romanize_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'romanize'

describe '#romanizeはひらがなをローマ字に変えられる' do
include Romanize


context 'ようおんを' do
it 'ローマ字に変えられる' do
expect( romanize('しんじゅく') ).to eq('sinzyuku')
end
end

context 'そくおん' do
it 'ローマ字に変えられる' do
expect( romanize('なっとう') ).to eq('nattou')
end
end

context 'ひらがなを' do
it 'ローマ字に変えられる' do
expect( romanize('ひらがな') ).to eq('hiragana')
end

it 'ローマ字に変えられる' do
expect( romanize('くつした') ).to eq('kutusita')
end
end
end