romaji 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +21 -0
- data/lib/romaji.rb +112 -0
- data/lib/romaji/constants.rb +79 -0
- data/lib/romaji/core_ext/string.rb +4 -0
- data/lib/romaji/string_extension.rb +30 -0
- data/lib/romaji/version.rb +5 -0
- data/romaji.gemspec +25 -0
- data/spec/romaji_spec.rb +94 -0
- data/spec/spec_helper.rb +8 -0
- metadata +174 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Shimpei Makimoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Romaji
|
2
|
+
|
3
|
+
[](http://travis-ci.org/makimoto/romaji)
|
4
|
+
|
5
|
+
Yet another Romaji-Kana transliterator.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ gem install romaji
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
require "romaji"
|
13
|
+
Romaji.kana2romaji "スシ" #=> "sushi"
|
14
|
+
Romaji.kana2romaji "sushi" #=> "スシ"
|
15
|
+
Romaji.kana2romaji "sushi", :kana_type => :hiragana #=> "すし"
|
16
|
+
|
17
|
+
require "romaji/core_ext/string"
|
18
|
+
"sushi".kana #=> "スシ"
|
19
|
+
"スシ".romaji #=> "sushi"
|
20
|
+
a = "sushi"
|
21
|
+
a.kana!
|
22
|
+
p a #=> "スシ"
|
23
|
+
a.romaji!
|
24
|
+
p a #=> "sushi"
|
25
|
+
|
26
|
+
|
27
|
+
## Author
|
28
|
+
|
29
|
+
Shimpei Makimoto
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
require 'bundler'
|
7
|
+
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
$stderr.puts e.message
|
12
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'rspec/core'
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new(:spec)
|
20
|
+
|
21
|
+
task :default => :spec
|
data/lib/romaji.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'nkf'
|
4
|
+
require 'romaji/string_extension'
|
5
|
+
require 'romaji/constants'
|
6
|
+
require 'romaji/version'
|
7
|
+
|
8
|
+
module Romaji
|
9
|
+
def self.romaji2kana(text, options = {})
|
10
|
+
text = hira2kata(self.normalize(text))
|
11
|
+
pos = 0
|
12
|
+
k = nil
|
13
|
+
kana = ''
|
14
|
+
chars = text.split(//u)
|
15
|
+
while true
|
16
|
+
# ン
|
17
|
+
if chars[pos] == 'm' && ['p', 'b', 'm'].include?(chars[pos + 1])
|
18
|
+
kana += 'ン'
|
19
|
+
pos += 1
|
20
|
+
next
|
21
|
+
end
|
22
|
+
|
23
|
+
# ッ
|
24
|
+
if chars[pos] == chars[pos + 1] && !['a', 'i', 'u', 'e', 'o', 'n'].include?(chars[pos])
|
25
|
+
kana += 'ッ'
|
26
|
+
pos += 1
|
27
|
+
next
|
28
|
+
end
|
29
|
+
|
30
|
+
ROMAJI_MAX_LENGTH.downto(1) do |t|
|
31
|
+
substr = chars.slice(pos, t).join
|
32
|
+
k = ROMAJI2KANA[substr]
|
33
|
+
if k
|
34
|
+
kana += k
|
35
|
+
pos += t
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
unless k
|
40
|
+
kana += chars.slice(pos, 1).join
|
41
|
+
pos += 1
|
42
|
+
end
|
43
|
+
break if pos >= chars.size
|
44
|
+
end
|
45
|
+
|
46
|
+
kana_type = options[:kana_type] || :katakana
|
47
|
+
kana = kata2hira(kana) if :hiragana == kana_type.to_sym
|
48
|
+
|
49
|
+
return kana
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.kana2romaji(text)
|
53
|
+
text = hira2kata(self.normalize(text))
|
54
|
+
pos = 0
|
55
|
+
k = nil
|
56
|
+
romaji = ''
|
57
|
+
chars = text.split(//u)
|
58
|
+
while true
|
59
|
+
# ン
|
60
|
+
if chars[pos] == 'ン'
|
61
|
+
next_char_romaji = KANA2ROMAJI[chars[pos + 1]]
|
62
|
+
if next_char_romaji && ['p', 'b', 'm'].include?(next_char_romaji[0].slice(0,1))
|
63
|
+
romaji += 'm'
|
64
|
+
else
|
65
|
+
romaji += 'n'
|
66
|
+
end
|
67
|
+
pos += 1
|
68
|
+
next
|
69
|
+
end
|
70
|
+
|
71
|
+
# ッ
|
72
|
+
if chars[pos] == 'ッ'
|
73
|
+
next_char_romaji = KANA2ROMAJI[chars[pos + 1]]
|
74
|
+
if ['a', 'i', 'u', 'e', 'o', 'n', nil].include?(chars[pos + 1])
|
75
|
+
romaji += 'xtsu'
|
76
|
+
else
|
77
|
+
romaji += (next_char_romaji[0].slice(0,1))
|
78
|
+
end
|
79
|
+
pos += 1
|
80
|
+
next
|
81
|
+
end
|
82
|
+
|
83
|
+
ROMAJI_MAX_LENGTH.downto(1) do |t|
|
84
|
+
substr = chars.slice(pos, t).join
|
85
|
+
k = KANA2ROMAJI[substr]
|
86
|
+
if k
|
87
|
+
romaji += k[0]
|
88
|
+
pos += t
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
unless k
|
93
|
+
romaji += chars.slice(pos, 1).join
|
94
|
+
pos += 1
|
95
|
+
end
|
96
|
+
break if pos >= chars.size
|
97
|
+
end
|
98
|
+
romaji
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.hira2kata(text)
|
102
|
+
NKF.nkf("--katakana -Ww", text)
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.kata2hira(text)
|
106
|
+
NKF.nkf("--hiragana -Ww", text)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.normalize(text)
|
110
|
+
NKF.nkf('-mZ0Wwh0', text).downcase
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Romaji
|
3
|
+
ROMAJI_MAX_LENGTH = 3
|
4
|
+
KANA_MAX_LENGTH = 3
|
5
|
+
|
6
|
+
ROMAJI2KANA = {
|
7
|
+
"a"=>"ア", "i"=>"イ", "u"=>"ウ", "e"=>"エ", "o"=>"オ", "-"=>"ー", "n" => "ン",
|
8
|
+
"xa"=>"ァ", "xi"=>"ィ", "xu"=>"ゥ", "xe"=>"ェ", "xo"=>"ォ",
|
9
|
+
"ka"=>"カ", "ki"=>"キ", "ku"=>"ク", "ke"=>"ケ", "ko"=>"コ",
|
10
|
+
"ca"=>"カ", "cu"=>"ク", "co"=>"コ",
|
11
|
+
"ga"=>"ガ", "gi"=>"ギ", "gu"=>"グ", "ge"=>"ゲ", "go"=>"ゴ",
|
12
|
+
"sa"=>"サ", "si"=>"シ", "su"=>"ス", "se"=>"セ", "so"=>"ソ",
|
13
|
+
"za"=>"ザ", "zi"=>"ジ", "zu"=>"ズ", "ze"=>"ゼ", "zo"=>"ゾ",
|
14
|
+
"ja"=>"ジャ","ji"=>"ジ", "ju"=>"ジュ","je"=>"ジェ","jo"=>"ジョ",
|
15
|
+
"ta"=>"タ", "ti"=>"チ", "tu"=>"ツ", "te"=>"テ", "to"=>"ト",
|
16
|
+
"da"=>"ダ", "di"=>"ヂ", "du"=>"ヅ", "de"=>"デ", "do"=>"ド",
|
17
|
+
"na"=>"ナ", "ni"=>"ニ", "nu"=>"ヌ", "ne"=>"ネ", "no"=>"ノ",
|
18
|
+
"ha"=>"ハ", "hi"=>"ヒ", "hu"=>"フ", "he"=>"ヘ", "ho"=>"ホ",
|
19
|
+
"ba"=>"バ", "bi"=>"ビ", "bu"=>"ブ", "be"=>"ベ", "bo"=>"ボ",
|
20
|
+
"pa"=>"パ", "pi"=>"ピ", "pu"=>"プ", "pe"=>"ペ", "po"=>"ポ",
|
21
|
+
"va"=>"ヴァ","vi"=>"ヴィ","vu"=>"ヴ", "ve"=>"ヴェ","vo"=>"ヴォ",
|
22
|
+
"fa"=>"ファ","fi"=>"フィ","fu"=>"フ", "fe"=>"フェ","fo"=>"フォ",
|
23
|
+
"ma"=>"マ", "mi"=>"ミ", "mu"=>"ム", "me"=>"メ", "mo"=>"モ",
|
24
|
+
"ya"=>"ヤ", "yi"=>"イ", "yu"=>"ユ", "ye"=>"イェ", "yo"=>"ヨ",
|
25
|
+
"ra"=>"ラ", "ri"=>"リ", "ru"=>"ル", "re"=>"レ", "ro"=>"ロ",
|
26
|
+
"la"=>"ラ", "li"=>"リ", "lu"=>"ル", "le"=>"レ", "lo"=>"ロ",
|
27
|
+
"wa"=>"ワ", "wi"=>"ヰ", "wu"=>"ウ", "we"=>"ヱ", "wo"=>"ヲ",
|
28
|
+
"nn"=>"ン", "n"=>"ン",
|
29
|
+
"tsu"=>"ツ",
|
30
|
+
"xka"=>"ヵ", "xke"=>"ヶ",
|
31
|
+
"xwa"=>"ヮ", "xtsu"=>"ッ", "xya"=>"ャ", "xyu"=>"ュ", "xyo"=>"ョ",
|
32
|
+
"kya"=>"キャ", "kyi"=>"キィ", "kyu"=>"キュ", "kye"=>"キェ", "kyo"=>"キョ",
|
33
|
+
"gya"=>"ギャ", "gyi"=>"ギィ", "gyu"=>"ギュ", "gye"=>"ギェ", "gyo"=>"ギョ",
|
34
|
+
"sya"=>"シャ", "syi"=>"シィ", "syu"=>"シュ", "sye"=>"シェ", "syo"=>"ショ",
|
35
|
+
"sha"=>"シャ", "shi"=>"シ", "shu"=>"シュ", "she"=>"シェ", "sho"=>"ショ",
|
36
|
+
"zya"=>"ジャ", "zyi"=>"ジィ", "zyu"=>"ジュ", "zye"=>"ジェ", "zyo"=>"ジョ",
|
37
|
+
"jya"=>"ジャ", "jyi"=>"ジィ", "jyu"=>"ジュ", "jye"=>"ジェ", "jyo"=>"ジョ",
|
38
|
+
"tya"=>"チャ", "tyi"=>"チィ", "tyu"=>"チュ", "tye"=>"チェ", "tyo"=>"チョ",
|
39
|
+
"cya"=>"チャ", "cyi"=>"チィ", "cyu"=>"チュ", "cye"=>"チェ", "cyo"=>"チョ",
|
40
|
+
"cha"=>"チャ", "chi"=>"チ", "chu"=>"チュ", "che"=>"チェ", "cho"=>"チョ",
|
41
|
+
"tha"=>"テャ", "thi"=>"ティ", "thu"=>"テュ", "the"=>"テェ", "tho"=>"テョ",
|
42
|
+
"dya"=>"ヂャ", "dyi"=>"ヂィ", "dyu"=>"ヂュ", "dye"=>"ヂェ", "dyo"=>"ヂョ",
|
43
|
+
"dha"=>"デャ", "dhi"=>"ディ", "dhu"=>"デュ", "dhe"=>"デェ", "dho"=>"デョ",
|
44
|
+
"nya"=>"ニャ", "nyi"=>"ニィ", "nyu"=>"ニュ", "nye"=>"ニェ", "nyo"=>"ニョ",
|
45
|
+
"hya"=>"ヒャ", "hyi"=>"ヒィ", "hyu"=>"ヒュ", "hye"=>"ヒェ", "hyo"=>"ヒョ",
|
46
|
+
"bya"=>"ビャ", "byi"=>"ビィ", "byu"=>"ビュ", "bye"=>"ビェ", "byo"=>"ビョ",
|
47
|
+
"pya"=>"ピャ", "pyi"=>"ピィ", "pyu"=>"ピュ", "pye"=>"ピェ", "pyo"=>"ピョ",
|
48
|
+
"mya"=>"ミャ", "myi"=>"ミィ", "myu"=>"ミュ", "mye"=>"ミェ", "myo"=>"ミョ",
|
49
|
+
"rya"=>"リャ", "ryi"=>"リィ", "ryu"=>"リュ", "rye"=>"リェ", "ryo"=>"リョ",
|
50
|
+
"lya"=>"リャ", "lyi"=>"リィ", "lyu"=>"リュ", "lye"=>"リェ", "lyo"=>"リョ"
|
51
|
+
}
|
52
|
+
|
53
|
+
KANA2ROMAJI = {
|
54
|
+
'ア' => ['a'], 'イ' => ['i'], 'ウ' => ['u'], 'エ' => ['e'], 'オ' => ['o'],
|
55
|
+
'カ' => ['ka', 'ca'], 'キ' => ['ki'], 'ク' => ['ku'], 'ケ' => ['ke'], 'コ' => ['ko', 'co'],
|
56
|
+
'サ' => ['sa'], 'シ' => ['shi', 'si'], 'ス' => ['su'], 'セ' => ['se'], 'ソ' => ['so'],
|
57
|
+
'タ' => ['ta'], 'チ' => ['chi', 'ti', 'ci'], 'ツ' => ['tsu', 'tu'], 'テ' => ['te'], 'ト' => ['to'],
|
58
|
+
'ナ' => ['na'], 'ニ' => ['ni'], 'ヌ' => ['nu'], 'ネ' => ['ne'], 'ノ' => ['no'],
|
59
|
+
'ハ' => ['ha'], 'ヒ' => ['hi'], 'フ' => ['fu', 'hu'], 'ヘ' => ['he'], 'ホ' => ['ho'],
|
60
|
+
'マ' => ['ma'], 'ミ' => ['mi'], 'ム' => ['mu'], 'メ' => ['me'], 'モ' => ['mo'],
|
61
|
+
'ヤ' => ['ya'], 'ユ' => ['yu'], 'ヨ' => ['yo'],
|
62
|
+
'ラ' => ['ra'], 'リ' => ['ri'], 'ル' => ['ru'], 'レ' => ['re'], 'ロ' => ['ro'],
|
63
|
+
'ワ' => ['wa'], 'ヲ' => ['wo'], 'ー' => ['-'],
|
64
|
+
'ガ' => ['ga'], 'ギ' => ['gi'], 'グ' => ['gu'], 'ゲ' => ['ge'], 'ゴ' => ['go'],
|
65
|
+
'ザ' => ['za'], 'ジ' => ['ji', 'zi'], 'ズ' => ['zu'], 'ゼ' => ['ze'], 'ゾ' => ['zo'],
|
66
|
+
'ダ' => ['da'], 'ヂ' => ['di'], 'ヅ' => ['du'], 'デ' => ['de'], 'ド' => ['do'],
|
67
|
+
'バ' => ['ba'], 'ビ' => ['bi'], 'ブ' => ['bu'], 'ベ' => ['be'], 'ボ' => ['bo'],
|
68
|
+
'パ' => ['pa'], 'ピ' => ['pi'], 'プ' => ['pu'], 'ペ' => ['pe'], 'ポ' => ['po'],
|
69
|
+
'キャ' => ['kya'], 'キュ' => ['kyu'], 'キェ' => ['kye'], 'キョ' => ['kyo'],
|
70
|
+
'ギャ' => ['gya'], 'ギュ' => ['gyu'], 'ギェ' => ['gye'], 'ギョ' => ['gyo'],
|
71
|
+
'シャ' => ['sha', 'sya'], 'シュ' => ['shu', 'syu'], 'シェ' => ['she', 'sye'], 'ショ' => ['sho', 'syo'],
|
72
|
+
'ジャ' => ['ja', 'jya', 'zya'], 'ジュ' => ['ju', 'jyu', 'zyu'], 'ジェ' => ['je', 'jye', 'zye'], 'ジョ' => ['jo', 'jyo', 'zyo'],
|
73
|
+
'チャ' => ['cha', 'cya', 'tya'], 'チュ' => ['chu', 'cyu', 'tyu'], 'チェ' => ['che', 'cye', 'tye'], 'チョ' => ['cho', 'cyo', 'tyo'],
|
74
|
+
'ヒャ' => ['hya'], 'ヒュ' => ['hyu'], 'ヒェ' => ['hye'], 'ヒョ' => ['hyo'],
|
75
|
+
'ピャ' => ['pya'], 'ピュ' => ['pyu'], 'ピェ' => ['pye'], 'ピョ' => ['pyo'],
|
76
|
+
'ファ' => ['fa'], 'フィ' => ['fi'], 'フェ' => ['fe'], 'フォ' => ['fo'],
|
77
|
+
'ヴァ' => ['va'], 'ヴィ' => ['vi'], 'ヴェ' => ['ve'], 'ヴォ' => ['fo'],
|
78
|
+
}
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
module Romaji
|
4
|
+
module StringExtension
|
5
|
+
def normalize
|
6
|
+
Romaji.normalize(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def normalize!
|
10
|
+
self.replace(self.normalize)
|
11
|
+
end
|
12
|
+
|
13
|
+
def kana
|
14
|
+
Romaji.romaji2kana(self.normalize)
|
15
|
+
end
|
16
|
+
|
17
|
+
def kana!
|
18
|
+
self.replace(self.kana)
|
19
|
+
end
|
20
|
+
|
21
|
+
def romaji
|
22
|
+
Romaji.kana2romaji(self.normalize)
|
23
|
+
end
|
24
|
+
|
25
|
+
def romaji!
|
26
|
+
self.replace(self.romaji)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/romaji.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
require 'romaji/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ['Shimpei Makimoto']
|
7
|
+
gem.email = ['makimoto@tsuyabu.in']
|
8
|
+
gem.description = 'Yet another Romaji-Kana transliterator'
|
9
|
+
gem.summary = 'Yet another Romaji-Kana transliterator'
|
10
|
+
gem.homepage = "https://github.com/makimoto/romaji"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = 'romaji'
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
gem.version = Romaji::VERSION
|
18
|
+
|
19
|
+
gem.add_dependency('rake', ['>= 0.8.0'])
|
20
|
+
gem.add_development_dependency('rspec', ['~> 2.8.0'])
|
21
|
+
gem.add_development_dependency('pry', ['>= 0'])
|
22
|
+
gem.add_development_dependency('guard', '>= 1.0.1')
|
23
|
+
gem.add_development_dependency('guard-rspec', '0.7.0')
|
24
|
+
gem.add_development_dependency('growl', '>= 1.0.3')
|
25
|
+
end
|
data/spec/romaji_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'romaji'
|
5
|
+
|
6
|
+
describe Romaji do
|
7
|
+
context 'transliterate from romaji to kana' do
|
8
|
+
it 'should transliterate' do
|
9
|
+
Romaji.romaji2kana('kyoumoshinaitone').should == 'キョウモシナイトネ'
|
10
|
+
Romaji.romaji2kana('今日もshinaitone').should == '今日モシナイトネ'
|
11
|
+
Romaji.romaji2kana('SushiNoTabetas').should == 'スシノタベタs'
|
12
|
+
Romaji.romaji2kana('shimbashi').should == 'シンバシ'
|
13
|
+
Romaji.romaji2kana('kinkakuji').should == 'キンカクジ'
|
14
|
+
Romaji.romaji2kana('tottori').should == 'トットリ'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should transliterate with kana_type' do
|
18
|
+
Romaji.romaji2kana('kyoumoshinaitone', :kana_type => :hiragana).should == 'きょうもしないとね'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should transliterate from kana to romaji' do
|
23
|
+
Romaji.kana2romaji('キョウモシナイトネ').should == 'kyoumoshinaitone'
|
24
|
+
Romaji.kana2romaji('すしのたべたさ').should == 'sushinotabetasa'
|
25
|
+
Romaji.kana2romaji('シンバシ').should == 'shimbashi'
|
26
|
+
Romaji.kana2romaji('キンカクジ').should == 'kinkakuji'
|
27
|
+
Romaji.kana2romaji('トットリ').should == 'tottori'
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_examples_for 'String extension' do
|
31
|
+
it 'should extend String#normalize' do
|
32
|
+
@kana.normalize.should == 'スシ'
|
33
|
+
@kana.should == 'スシ'
|
34
|
+
|
35
|
+
@romaji.normalize.should == 'sushi'
|
36
|
+
@romaji.should == 'sUshi'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should extend String#normalize!' do
|
40
|
+
@kana.normalize!
|
41
|
+
@kana.should == 'スシ'
|
42
|
+
|
43
|
+
@romaji.normalize!
|
44
|
+
@romaji.should == 'sushi'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should extend String#kana' do
|
48
|
+
@kana.kana.should == 'スシ'
|
49
|
+
@romaji.kana.should == 'スシ'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should extend String#kana!' do
|
53
|
+
@kana.kana!
|
54
|
+
@kana.should == 'スシ'
|
55
|
+
|
56
|
+
@romaji.kana!
|
57
|
+
@romaji.should == 'スシ'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should extend String#romaji' do
|
61
|
+
@kana.romaji.should =='sushi'
|
62
|
+
@romaji.romaji.should == 'sushi'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should extend String#romaji!' do
|
66
|
+
@kana.romaji!
|
67
|
+
@kana.should == 'sushi'
|
68
|
+
|
69
|
+
@romaji.romaji!
|
70
|
+
@romaji.should == 'sushi'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe Romaji::StringExtension do
|
75
|
+
before do
|
76
|
+
@kana = 'スシ'
|
77
|
+
@romaji = 'sUshi'
|
78
|
+
@kana.extend(Romaji::StringExtension)
|
79
|
+
@romaji.extend(Romaji::StringExtension)
|
80
|
+
end
|
81
|
+
|
82
|
+
it_behaves_like 'String extension'
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'romaji/core_ext/string' do
|
86
|
+
require 'romaji/core_ext/string'
|
87
|
+
before do
|
88
|
+
@kana = 'スシ'
|
89
|
+
@romaji = 'sUshi'
|
90
|
+
end
|
91
|
+
|
92
|
+
it_behaves_like 'String extension'
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: romaji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Shimpei Makimoto
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 63
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 8
|
32
|
+
- 0
|
33
|
+
version: 0.8.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 47
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 8
|
48
|
+
- 0
|
49
|
+
version: 2.8.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: pry
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: guard
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 21
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 0
|
78
|
+
- 1
|
79
|
+
version: 1.0.1
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: guard-rspec
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - "="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
- 7
|
94
|
+
- 0
|
95
|
+
version: 0.7.0
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: growl
|
100
|
+
prerelease: false
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 17
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 0
|
110
|
+
- 3
|
111
|
+
version: 1.0.3
|
112
|
+
type: :development
|
113
|
+
version_requirements: *id006
|
114
|
+
description: Yet another Romaji-Kana transliterator
|
115
|
+
email:
|
116
|
+
- makimoto@tsuyabu.in
|
117
|
+
executables: []
|
118
|
+
|
119
|
+
extensions: []
|
120
|
+
|
121
|
+
extra_rdoc_files: []
|
122
|
+
|
123
|
+
files:
|
124
|
+
- .rspec
|
125
|
+
- .travis.yml
|
126
|
+
- Gemfile
|
127
|
+
- Guardfile
|
128
|
+
- LICENSE
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- lib/romaji.rb
|
132
|
+
- lib/romaji/constants.rb
|
133
|
+
- lib/romaji/core_ext/string.rb
|
134
|
+
- lib/romaji/string_extension.rb
|
135
|
+
- lib/romaji/version.rb
|
136
|
+
- romaji.gemspec
|
137
|
+
- spec/romaji_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/makimoto/romaji
|
140
|
+
licenses: []
|
141
|
+
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
hash: 3
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
version: "0"
|
165
|
+
requirements: []
|
166
|
+
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 1.8.17
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: Yet another Romaji-Kana transliterator
|
172
|
+
test_files:
|
173
|
+
- spec/romaji_spec.rb
|
174
|
+
- spec/spec_helper.rb
|