romankana 0.1.3 → 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/README.rdoc +3 -0
- data/Rakefile +9 -26
- data/lib/romankana/k2r.rb +1 -4
- data/lib/romankana/r2k.rb +1 -1
- data/lib/romankana/romankana.rb +55 -120
- data/lib/romankana/string.rb +40 -0
- data/lib/romankana/utils.rb +13 -0
- data/lib/romankana/version.rb +3 -0
- data/lib/romankana.rb +5 -3
- data/romankana.gemspec +23 -0
- data/script/console +2 -2
- data/spec/romankana_spec.rb +208 -26
- data/spec/spec_helper.rb +2 -0
- data/spec/string_spec.rb +55 -0
- data/tasks/rspec.rake +5 -5
- metadata +55 -42
- data/.gemtest +0 -0
- data/History.txt +0 -4
- data/PostInstall.txt +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfa46d42b2de0371896cd3d454a4fd64ff61fecf
|
4
|
+
data.tar.gz: 21b33444b783f0363b5356fbe39c319770c141d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f49f33cb537e6bb6c4429675f844675cc10348bc885425bd70d9650cb65c515fc8e565231cc66a78cb4974efd1aa32c19e30f58754e1ebf7ea8728e2f15b6cbf
|
7
|
+
data.tar.gz: 496856e117740d2b09b1cd00da4c5475659140c934944cde2479df13e839b2d659336deb31a65069bdcf48ce1be911dcc4db95ba8ffa11d9ad8b1cd63a20f80b
|
data/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
.*.swp
|
2
|
+
.*.swo
|
3
|
+
*~
|
4
|
+
pkg/*
|
5
|
+
|
6
|
+
.DS_Store
|
7
|
+
|
8
|
+
nbproject/private/rake-d.txt
|
9
|
+
|
10
|
+
nbproject/project.properties
|
11
|
+
|
12
|
+
nbproject/project.xml
|
13
|
+
|
14
|
+
*.gem
|
15
|
+
*.rbc
|
16
|
+
.bundle
|
17
|
+
.config
|
18
|
+
.yardoc
|
19
|
+
Gemfile.lock
|
20
|
+
InstalledFiles
|
21
|
+
_yardoc
|
22
|
+
coverage
|
23
|
+
doc/
|
24
|
+
lib/bundler/man
|
25
|
+
pkg
|
26
|
+
rdoc
|
27
|
+
spec/reports
|
28
|
+
test/tmp
|
29
|
+
test/version_tmp
|
30
|
+
tmp
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
= RomanKana:
|
2
|
+
{<img src="https://travis-ci.org/ymrl/romankana.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/ymrl/romankana]
|
3
|
+
{<img src="https://coveralls.io/repos/ymrl/romankana/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/ymrl/romankana]
|
4
|
+
|
2
5
|
|
3
6
|
* https://github.com/ymrl/romankana
|
4
7
|
|
data/Rakefile
CHANGED
@@ -1,26 +1,9 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# Generate all the Rake tasks
|
12
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec 'romankana' do
|
14
|
-
self.developer 'ymrl', 'ymrl@ymrl.net'
|
15
|
-
#self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
-
self.rubyforge_name = self.name # TODO this is default value
|
17
|
-
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'newgem/tasks'
|
22
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
-
|
24
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
-
# remove_task :default
|
26
|
-
# task :default => [:spec, :features]
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new do |spec|
|
5
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
6
|
+
#spec.rspec_opts = ['--backtrace']
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default => [:spec]
|
data/lib/romankana/k2r.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#coding:utf-8
|
2
2
|
module RomanKana
|
3
|
-
|
3
|
+
K2R_TABLE = {
|
4
4
|
'ア' => 'a',
|
5
5
|
'イ' => 'i',
|
6
6
|
'ウ' => 'u',
|
@@ -74,9 +74,6 @@ module RomanKana
|
|
74
74
|
'プ' => 'pu',
|
75
75
|
'ペ' => 'pe',
|
76
76
|
'ポ' => 'po',
|
77
|
-
'ー' => '',
|
78
|
-
}
|
79
|
-
K2R_table_2 = {
|
80
77
|
'キャ' => 'kya',
|
81
78
|
'キュ' => 'kyu',
|
82
79
|
'キョ' => 'kyo',
|
data/lib/romankana/r2k.rb
CHANGED
data/lib/romankana/romankana.rb
CHANGED
@@ -3,135 +3,70 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
4
|
|
5
5
|
require 'kconv'
|
6
|
+
require 'utils'
|
6
7
|
|
7
8
|
module RomanKana
|
9
|
+
def self.find_kana_from_str str
|
10
|
+
return '' if !str || str.length == 0
|
11
|
+
found = R2K_TABLE[str]
|
12
|
+
if found
|
13
|
+
return found
|
14
|
+
elsif str.length >= 2 && str[0] == 'n' && str[1] == 'n'
|
15
|
+
return "ン#{find_kana_from_str(str[2..-1])}"
|
16
|
+
elsif str.length > 2 && str[0] == 'n' && str[1] !~ /[aiueoy]/
|
17
|
+
return "ン#{find_kana_from_str(str[1..-1])}"
|
18
|
+
elsif str.length > 2 && str[0] == 'm' && str[1] =~ /[bmp]/
|
19
|
+
return "ン#{find_kana_from_str(str[1..-1])}"
|
20
|
+
elsif str.length >= 2 && str[0] == str[1] && str[0] =~ /[bcdfghjklmnpqrstvwxyz]/
|
21
|
+
return "ッ#{find_kana_from_str(str[1..-1])}"
|
22
|
+
elsif str.length >= 2
|
23
|
+
return "#{find_kana_from_str(str[0])}#{find_kana_from_str(str[1..-1])}"
|
24
|
+
else
|
25
|
+
return str
|
26
|
+
end
|
27
|
+
end
|
8
28
|
|
9
|
-
def
|
10
|
-
str = RomanKana.convert_utf8(str)
|
29
|
+
def self.romankana str
|
30
|
+
str = RomanKana::Utils.convert_utf8(str)
|
11
31
|
ret = ''
|
12
|
-
array = NKF.nkf('-WwZ0',str).downcase.split(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ret += a
|
18
|
-
buff.clear
|
19
|
-
elsif buff.length >=2 and buff[0] == 'n' and buff[1] !~ /[aeiouy]/
|
20
|
-
ret += 'ン'
|
21
|
-
buff.shift
|
22
|
-
elsif i == array.length and buff[0] == 'n'
|
23
|
-
ret += 'ン'
|
24
|
-
buff.shift
|
25
|
-
elsif buff.length >=2 and buff[0] == 'm' and buff[1] =~ /[bmp]/
|
26
|
-
ret += 'ン'
|
27
|
-
buff.shift
|
28
|
-
elsif buff.length >= 2 and buff[0] == buff[1] and buff[0] =~ /[a-z]/
|
29
|
-
ret += 'ッ'
|
30
|
-
buff.shift
|
31
|
-
elsif buff.length >= 3
|
32
|
-
ret += buff.shift
|
33
|
-
next
|
34
|
-
end
|
35
|
-
buff << array[i]
|
36
|
-
i += 1
|
37
|
-
end
|
38
|
-
return ret+buff.join('')
|
32
|
+
array = NKF.nkf('-WwZ0',str).downcase.split(/([^a-z])/).map do |e|
|
33
|
+
e.split(/([^aiueo]*[aiueo])/).delete_if{|e|e.length == 0}
|
34
|
+
end.flatten
|
35
|
+
ret = array.map{|e| find_kana_from_str e }
|
36
|
+
return ret.join('')
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
str = RomanKana.convert_utf8(str)
|
43
|
-
ret =
|
44
|
-
|
45
|
-
|
46
|
-
array
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
buff = [array.first]
|
55
|
-
i = 1
|
56
|
-
while i <= array.length
|
57
|
-
if a = RomanKana::K2R_table_2[buff.join('')]
|
58
|
-
ret << a
|
59
|
-
buff.clear
|
60
|
-
next if i == array.length
|
61
|
-
elsif a = RomanKana::K2R_table_2[buff[0]]
|
62
|
-
ret << a
|
63
|
-
buff.shift
|
64
|
-
next if i == array.length
|
65
|
-
elsif buff.length >= 2 && a = RomanKana::K2R_table_1[buff[0,buff.length-1].join('')]
|
66
|
-
ret << a
|
67
|
-
(buff.length-1).times{buff.shift}
|
68
|
-
next if i == array.length
|
69
|
-
elsif i == array.length && a = RomanKana::K2R_table_1[buff.join('')]
|
70
|
-
ret << a
|
71
|
-
buff.clear
|
72
|
-
next if i == array.length
|
73
|
-
elsif buff.length >= 2
|
74
|
-
ret << buff.shift
|
75
|
-
next
|
39
|
+
def self.kanaroman str
|
40
|
+
str = RomanKana::Utils.convert_utf8(str)
|
41
|
+
ret = nil
|
42
|
+
|
43
|
+
temp = NKF.nkf('-Wwh2',str).split('')
|
44
|
+
array = []
|
45
|
+
temp.each_with_index do |s,i|
|
46
|
+
if i + 1 < temp.length
|
47
|
+
next_str = temp[i+1]
|
48
|
+
if next_str =~ /[ァィゥェォャュョ]/u
|
49
|
+
s = "#{s}#{next_str}"
|
50
|
+
temp[i+1] = nil
|
51
|
+
end
|
76
52
|
end
|
77
|
-
|
78
|
-
i += 1
|
53
|
+
array.push s if s
|
79
54
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
55
|
+
|
56
|
+
ret = array.map{|e| K2R_TABLE[e] || e }
|
57
|
+
ret.each_with_index do |s,i|
|
58
|
+
if s == 'ッ'
|
59
|
+
if i + 1 < ret.length
|
60
|
+
c = ret[i+1].split('').first
|
61
|
+
ret[i] = c if c !~ /[aiueo]/
|
62
|
+
end
|
63
|
+
elsif s == 'ー'
|
64
|
+
if i - 1 >= 0
|
65
|
+
c = ret[i-1].split('').last
|
66
|
+
ret[i] = c if c =~ /[aiueo]/
|
67
|
+
end
|
68
|
+
end
|
83
69
|
end
|
84
70
|
return ret.join('')
|
85
71
|
end
|
86
|
-
def RomanKana.set_encoding_of_before before, after
|
87
|
-
if RUBY_VERSION < "1.9"
|
88
|
-
return Kconv.guess(before) == Kconv::ASCII ? after : Kconv.kconv(after,Kconv.guess(before),Kconv::UTF8)
|
89
|
-
end
|
90
|
-
e = before.encoding
|
91
|
-
return (e == Encoding::US_ASCII or e == Encoding::ASCII_8BIT) ? after : after.encode(e)
|
92
|
-
end
|
93
|
-
def RomanKana.convert_utf8 str
|
94
|
-
if RUBY_VERSION < "1.9"
|
95
|
-
return str.toutf8
|
96
|
-
else
|
97
|
-
return (str.encoding != Encoding::UTF_8) ? str.encode(Encoding::UTF_8) : str
|
98
|
-
end
|
99
|
-
end
|
100
72
|
end
|
101
|
-
|
102
|
-
|
103
|
-
class String
|
104
|
-
def roman_to_hiragana
|
105
|
-
r = self.split(/([a-zA-Z]+)/u).map{|e|e =~ /[a-zA-Z]+/u?NKF.nkf("-Wwh1",RomanKana.romankana(e)):e}.join('')
|
106
|
-
return RomanKana.set_encoding_of_before(self,r)
|
107
|
-
end
|
108
|
-
def roman_to_katakana
|
109
|
-
r = self.split(/([a-zA-Z]+)/u).map{|e|e =~ /[a-zA-Z]+/u?RomanKana.romankana(e):e}.join('')
|
110
|
-
return RomanKana.set_encoding_of_before(self,r)
|
111
|
-
end
|
112
|
-
def katakana_to_roman
|
113
|
-
r = self.split(/([ァ-ヴ]+)/u).map{|e|e =~ /[ァ-ヴ]+/u?RomanKana.kanaroman(e):e}.join('')
|
114
|
-
return RomanKana.set_encoding_of_before(self,r)
|
115
|
-
end
|
116
|
-
def hiragana_to_roman
|
117
|
-
r = self.split(/([ぁ-ゔ]+)/u).map{|e|e =~ /[ぁ-ゔ]+/u?NKF.nkf("-Wwh1",RomanKana.kanaroman(e)):e}.join('')
|
118
|
-
return RomanKana.set_encoding_of_before(self,r)
|
119
|
-
end
|
120
|
-
def to_roman
|
121
|
-
r = RomanKana.kanaroman(self)
|
122
|
-
return RomanKana.set_encoding_of_before(self,r)
|
123
|
-
end
|
124
|
-
def to_hiragana
|
125
|
-
r = NKF.nkf('-Wwh1',RomanKana.romankana(self))
|
126
|
-
return RomanKana.set_encoding_of_before(self,r)
|
127
|
-
end
|
128
|
-
def to_katakana
|
129
|
-
r = NKF.nkf('-Wwh2',RomanKana.romankana(self))
|
130
|
-
return RomanKana.set_encoding_of_before(self,r)
|
131
|
-
end
|
132
|
-
def to_hankaku
|
133
|
-
r = NKF.nkf('-Z4xwW',RomanKana.convert_utf8(self))
|
134
|
-
return RomanKana.set_encoding_of_before(self,r)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#coding:UTF-8
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
require 'romankana'
|
6
|
+
|
7
|
+
class String
|
8
|
+
def roman_to_hiragana
|
9
|
+
r = self.split(/([a-zA-Z]+)/u).map{|e|e =~ /[a-zA-Z]+/u?NKF.nkf("-Wwh1",RomanKana.romankana(e)):e}.join('')
|
10
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
11
|
+
end
|
12
|
+
def roman_to_katakana
|
13
|
+
r = self.split(/([a-zA-Z]+)/u).map{|e|e =~ /[a-zA-Z]+/u?RomanKana.romankana(e):e}.join('')
|
14
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
15
|
+
end
|
16
|
+
def katakana_to_roman
|
17
|
+
r = self.split(/([ァ-ヴ]+)/u).map{|e|e =~ /[ァ-ヴ]+/u?RomanKana.kanaroman(e):e}.join('')
|
18
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
19
|
+
end
|
20
|
+
def hiragana_to_roman
|
21
|
+
r = self.split(/([ぁ-ゔ]+)/u).map{|e|e =~ /[ぁ-ゔ]+/u?NKF.nkf("-Wwh1",RomanKana.kanaroman(e)):e}.join('')
|
22
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
23
|
+
end
|
24
|
+
def to_roman
|
25
|
+
r = RomanKana.kanaroman(self)
|
26
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
27
|
+
end
|
28
|
+
def to_hiragana
|
29
|
+
r = NKF.nkf('-Wwh1',RomanKana.romankana(self))
|
30
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
31
|
+
end
|
32
|
+
def to_katakana
|
33
|
+
r = NKF.nkf('-Wwh2',RomanKana.romankana(self))
|
34
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
35
|
+
end
|
36
|
+
def to_hankaku
|
37
|
+
r = NKF.nkf('-Z4xwW',RomanKana::Utils.convert_utf8(self))
|
38
|
+
return RomanKana::Utils.set_encoding_of_before(self,r)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RomanKana
|
2
|
+
module Utils
|
3
|
+
def self.set_encoding_of_before before, after
|
4
|
+
e = before.encoding
|
5
|
+
return (e == Encoding::US_ASCII or e == Encoding::ASCII_8BIT) ? after : after.encode(e)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.convert_utf8 str
|
9
|
+
return (str.encoding != Encoding::UTF_8) ? str.encode(Encoding::UTF_8) : str
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/lib/romankana.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#coding:utf-8
|
2
2
|
$:.unshift(File.dirname(__FILE__)) unless
|
3
3
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
-
|
4
|
+
|
5
5
|
directory = File.expand_path(File.dirname(__FILE__))
|
6
6
|
require directory+'/romankana/r2k.rb'
|
7
7
|
require directory+'/romankana/k2r.rb'
|
8
|
+
require directory+'/romankana/utils.rb'
|
8
9
|
require directory+'/romankana/romankana.rb'
|
9
|
-
|
10
|
+
require directory+'/romankana/string.rb'
|
11
|
+
require directory+'/romankana/version.rb'
|
12
|
+
|
10
13
|
module RomanKana
|
11
|
-
VERSION = '0.1.3'
|
12
14
|
end
|
data/romankana.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'romankana/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "romankana"
|
7
|
+
spec.version = RomanKana::VERSION
|
8
|
+
spec.authors = ["ymrl"]
|
9
|
+
spec.email = ["ymrl@ymrl.net"]
|
10
|
+
spec.summary = %q{Roman Alphabet <-> Japanese Hiragana/Katkakana Convert Library for Ruby}
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = "https://github.com/ymrl/romankana"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
data/script/console
CHANGED
@@ -5,6 +5,6 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
5
5
|
libs = " -r irb/completion"
|
6
6
|
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
7
|
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/romankana.rb'}"
|
9
9
|
puts "Loading romankana gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/spec/romankana_spec.rb
CHANGED
@@ -1,31 +1,213 @@
|
|
1
|
-
#coding:UTF-8
|
2
|
-
#require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
-
puts File.expand_path(File.dirname(__FILE__))
|
1
|
+
# coding:UTF-8
|
4
2
|
require 'spec_helper.rb'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
describe "
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
'
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
describe RomanKana do
|
5
|
+
|
6
|
+
describe "#find_kana_from_str" do
|
7
|
+
let(:given){ '' }
|
8
|
+
before do
|
9
|
+
@got = RomanKana.find_kana_from_str given
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'non-alphabet string given' do
|
13
|
+
let(:given){ 'あ' }
|
14
|
+
|
15
|
+
it 'returns given string' do
|
16
|
+
expect(@got).to eq given
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'string starts with nn given' do
|
21
|
+
let(:given){ 'nnya' }
|
22
|
+
|
23
|
+
it 'returns ン...' do
|
24
|
+
expect(@got).to eq 'ンヤ'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'string stats with n given' do
|
29
|
+
context 'next to consonant' do
|
30
|
+
let(:given){ 'nga' }
|
31
|
+
|
32
|
+
it 'returns ンガ' do
|
33
|
+
expect(@got).to eq 'ンガ'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context 'next to vowel' do
|
37
|
+
let(:given){ 'nya' }
|
38
|
+
|
39
|
+
it 'returns ニャ' do
|
40
|
+
expect(@got).to eq 'ニャ'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'string stats with m given' do
|
46
|
+
context 'means ン' do
|
47
|
+
let(:given){ 'mba' }
|
48
|
+
|
49
|
+
it 'returns ンバ' do
|
50
|
+
expect(@got).to eq 'ンバ'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'next to vowel' do
|
55
|
+
let(:given){ 'ma' }
|
56
|
+
|
57
|
+
it 'returns マ' do
|
58
|
+
expect(@got).to eq 'マ'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'nonsense' do
|
63
|
+
let(:given){ 'mdo' }
|
64
|
+
|
65
|
+
it 'returns mド' do
|
66
|
+
expect(@got).to eq 'mド'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'string starts with same 2 alphabet given' do
|
72
|
+
context 'that is consonant' do
|
73
|
+
let(:given){'tto'}
|
74
|
+
|
75
|
+
it 'returns ット' do
|
76
|
+
expect(@got).to eq 'ット'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'that is vowel' do
|
81
|
+
let(:given){'aada'}
|
82
|
+
|
83
|
+
it 'returns アアダ' do
|
84
|
+
expect(@got).to eq 'アアダ'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'long string given' do
|
90
|
+
let(:given){ 'aaaaaaaa' }
|
91
|
+
|
92
|
+
it 'returns アアアアアアア' do
|
93
|
+
expect(@got).to eq 'アアアアアアアア'
|
94
|
+
end
|
95
|
+
end
|
19
96
|
end
|
20
|
-
|
21
|
-
describe "
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
'
|
28
|
-
|
29
|
-
|
97
|
+
|
98
|
+
describe "#romankana" do
|
99
|
+
let(:given){ '' }
|
100
|
+
before do
|
101
|
+
@got = RomanKana.romankana given
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'hiragana given' do
|
105
|
+
let(:given) { 'あのいーはとーゔぉのすきとおったかぜ' }
|
106
|
+
|
107
|
+
it 'does nothing' do
|
108
|
+
expect(@got).to eq given
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'katakana given' do
|
113
|
+
let(:given) { 'アノイーハトーヴォノスキトオッタカゼ' }
|
114
|
+
|
115
|
+
it 'does nothing' do
|
116
|
+
expect(@got).to eq given
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
context 'roman-ji given' do
|
123
|
+
let(:given) { 'ano iihatoovo no sukitootta kaze' }
|
124
|
+
it 'returns katakana' do
|
125
|
+
expect(@got).to eq 'アノ イイハトオヴォ ノ スキトオッタ カゼ'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'ン given' do
|
130
|
+
context 'in nn' do
|
131
|
+
let(:given){'kouennji himonnya'}
|
132
|
+
|
133
|
+
it 'handles nn as ン' do
|
134
|
+
expect(@got).to eq 'コウエンジ ヒモンヤ'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'in n' do
|
139
|
+
let(:given){'kouenji himonya'}
|
140
|
+
|
141
|
+
it 'handles n as ン' do
|
142
|
+
expect(@got).to eq 'コウエンジ ヒモニャ'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'the Hepburn system given' do
|
148
|
+
let(:given){'nishinippori hambaagu'}
|
149
|
+
|
150
|
+
it 'handles in the Hepburn system' do
|
151
|
+
expect(@got).to eq 'ニシニッポリ ハンバアグ'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'the kunrei system given' do
|
156
|
+
let(:given){'nisinippori hanbaagu'}
|
157
|
+
|
158
|
+
it 'handles in the kunrei system' do
|
159
|
+
expect(@got).to eq 'ニシニッポリ ハンバアグ'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#kanaroman" do
|
165
|
+
let(:given){ '' }
|
166
|
+
before do
|
167
|
+
@got = RomanKana.kanaroman given
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'roman-ji given' do
|
171
|
+
let(:given) { 'ano iihatoovo no sukitootta kaze' }
|
172
|
+
|
173
|
+
it 'does nothing' do
|
174
|
+
expect(@got).to eq given
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'hiragana given' do
|
179
|
+
let(:given) { 'あのいーはとーゔぉのすきとおったかぜ' }
|
180
|
+
|
181
|
+
it 'converts to roman-ji' do
|
182
|
+
expect(@got).to eq 'anoiihatoovonosukitoottakaze'
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'katakana given' do
|
188
|
+
let(:given) { 'アノイーハトーヴォノスキトオッタカゼ' }
|
189
|
+
|
190
|
+
it 'converts to roman-ji' do
|
191
|
+
expect(@got).to eq 'anoiihatoovonosukitoottakaze'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'ン given' do
|
196
|
+
context 'in nn' do
|
197
|
+
let(:given){'コウエンジ ヒモンヤ'}
|
198
|
+
|
199
|
+
it 'handles ン' do
|
200
|
+
expect(@got).to eq 'kouenji himonya'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'ー and ッ given' do
|
206
|
+
let(:given){'マークザッカーバーグ アーノルドシュワルツネッガー'}
|
207
|
+
|
208
|
+
it 'changes ー' do
|
209
|
+
expect(@got).to eq 'maakuzakkaabaagu aanorudoshuwarutsuneggaa'
|
210
|
+
end
|
211
|
+
end
|
30
212
|
end
|
31
213
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#coding:UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
describe '#roman_to_hiragana' do
|
6
|
+
it 'converts roman-ji to hiragana' do
|
7
|
+
expect('ほげほげhogehogeホゲホゲ'.roman_to_hiragana).to eq 'ほげほげほげほげホゲホゲ'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#roman_to_katakana' do
|
12
|
+
it 'converts roman-ji to katakana' do
|
13
|
+
expect('ほげほげhogehogeホゲホゲ'.roman_to_katakana).to eq 'ほげほげホゲホゲホゲホゲ'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#katakana_to_roman' do
|
18
|
+
it 'converts katakana to roman' do
|
19
|
+
expect('ほげほげhogehogeホゲホゲ'.katakana_to_roman).to eq 'ほげほげhogehogehogehoge'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#hiragana_to_roman' do
|
24
|
+
it 'converts hiragana to roman' do
|
25
|
+
expect('ほげほげhogehogeホゲホゲ'.hiragana_to_roman).to eq 'hogehogehogehogeホゲホゲ'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#to_roman' do
|
30
|
+
it 'converts all kana to roman' do
|
31
|
+
expect('ほげほげhogehogeホゲホゲ'.to_roman).to eq 'hogehogehogehogehogehoge'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
describe '#to_hiragana' do
|
37
|
+
it 'converts all roman-ji and katakana to hiragana' do
|
38
|
+
expect('ほげほげhogehogeホゲホゲ'.to_hiragana).to eq 'ほげほげほげほげほげほげ'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#to_katakana' do
|
43
|
+
it 'converts all roman-ji and hiragana to katakana' do
|
44
|
+
expect('ほげほげhogehogeホゲホゲ'.to_katakana).to eq 'ホゲホゲホゲホゲホゲホゲ'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe '#to_hankaku' do
|
50
|
+
it 'converts katkana and zenkaku alphabet to hankaku' do
|
51
|
+
expect('ほげほげhogehogeホゲホゲhogehoge'.to_hankaku).to eq 'ほげほげhogehogeホゲホゲhogehoge'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/tasks/rspec.rake
CHANGED
@@ -14,8 +14,8 @@ EOS
|
|
14
14
|
exit(0)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
RSpec::Core::RakeTask.new do |t|
|
19
|
+
t.rspec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.pattern = 'spec/**/*_spec.rb'
|
21
|
+
end
|
metadata
CHANGED
@@ -1,102 +1,115 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: romankana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- ymrl
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '1.5'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
+
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
47
|
+
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Roman Alphabet <-> Japanese Hiragana/Katkakana Convert Library for Ruby
|
48
56
|
email:
|
49
57
|
- ymrl@ymrl.net
|
50
58
|
executables: []
|
51
59
|
extensions: []
|
52
|
-
extra_rdoc_files:
|
53
|
-
- History.txt
|
54
|
-
- Manifest.txt
|
55
|
-
- PostInstall.txt
|
56
|
-
- README.rdoc
|
60
|
+
extra_rdoc_files: []
|
57
61
|
files:
|
58
|
-
-
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
59
65
|
- Manifest.txt
|
60
|
-
- PostInstall.txt
|
61
66
|
- README.rdoc
|
62
67
|
- Rakefile
|
63
68
|
- lib/romankana.rb
|
64
|
-
- lib/romankana/romankana.rb
|
65
|
-
- lib/romankana/r2k.rb
|
66
69
|
- lib/romankana/k2r.rb
|
70
|
+
- lib/romankana/r2k.rb
|
71
|
+
- lib/romankana/romankana.rb
|
72
|
+
- lib/romankana/string.rb
|
73
|
+
- lib/romankana/utils.rb
|
74
|
+
- lib/romankana/version.rb
|
75
|
+
- romankana.gemspec
|
67
76
|
- script/console
|
68
77
|
- script/destroy
|
69
78
|
- script/generate
|
70
79
|
- spec/romankana_spec.rb
|
71
80
|
- spec/spec.opts
|
72
81
|
- spec/spec_helper.rb
|
82
|
+
- spec/string_spec.rb
|
73
83
|
- tasks/rspec.rake
|
74
84
|
- test/romankana_test.rb
|
75
|
-
- .gemtest
|
76
85
|
homepage: https://github.com/ymrl/romankana
|
77
|
-
licenses:
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
78
89
|
post_install_message:
|
79
|
-
rdoc_options:
|
80
|
-
- --main
|
81
|
-
- README.rdoc
|
90
|
+
rdoc_options: []
|
82
91
|
require_paths:
|
83
92
|
- lib
|
84
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
94
|
requirements:
|
87
|
-
- -
|
95
|
+
- - '>='
|
88
96
|
- !ruby/object:Gem::Version
|
89
97
|
version: '0'
|
90
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
99
|
requirements:
|
93
|
-
- -
|
100
|
+
- - '>='
|
94
101
|
- !ruby/object:Gem::Version
|
95
102
|
version: '0'
|
96
103
|
requirements: []
|
97
|
-
rubyforge_project:
|
98
|
-
rubygems_version:
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.0.3
|
99
106
|
signing_key:
|
100
|
-
specification_version:
|
107
|
+
specification_version: 4
|
101
108
|
summary: Roman Alphabet <-> Japanese Hiragana/Katkakana Convert Library for Ruby
|
102
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- spec/romankana_spec.rb
|
111
|
+
- spec/spec.opts
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/string_spec.rb
|
114
|
+
- test/romankana_test.rb
|
115
|
+
has_rdoc:
|
data/.gemtest
DELETED
File without changes
|
data/History.txt
DELETED