romajify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +9 -0
- data/.yardopts +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/romajify +3 -0
- data/lib/romajify.rb +2 -0
- data/lib/romajify/cli.rb +49 -0
- data/lib/romajify/converter.rb +234 -0
- data/lib/romajify/version.rb +3 -0
- data/romajify.gemspec +31 -0
- metadata +190 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eed94c41b7dc994504a38079fae3ee8e1389b784
|
4
|
+
data.tar.gz: 3c5ab55eaef4d334206d682f2ed0f498267340c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7144c883fcf7a026cc9cc5c8d69ba8e7cafca3fda3e66ae63d11811940fff29c88f9d4cfddaa8aa669b6792ef171ca120e3db62416d1b5f56ef70bea623a4389
|
7
|
+
data.tar.gz: c210918ff97d8fbe73d7612a799e083a8089289ec605acbcf4423b801d47dfb9d2c5cb17795942ffb47b69087fe76b8e923ca476ea6bd8c230f23923fe1eff68
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/AsciiComments:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/EmptyLinesAroundModuleBody:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/MutableConstant:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/PercentLiteralDelimiters:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/UnneededPercentQ:
|
17
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 emsk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Romajify
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/emsk/romajify.svg?branch=master)](https://travis-ci.org/emsk/romajify)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/emsk/romajify/badge.svg?branch=master)](https://coveralls.io/github/emsk/romajify)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/emsk/romajify/badges/gpa.svg)](https://codeclimate.com/github/emsk/romajify)
|
6
|
+
[![Dependency Status](https://gemnasium.com/emsk/romajify.svg)](https://gemnasium.com/emsk/romajify)
|
7
|
+
[![Inline docs](http://inch-ci.org/github/emsk/romajify.svg?branch=master)](http://inch-ci.org/github/emsk/romajify)
|
8
|
+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
|
9
|
+
|
10
|
+
Japanese romanization library for Ruby.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'romajify'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ gem install romajify
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
#### Command Line Interface
|
35
|
+
|
36
|
+
```sh
|
37
|
+
$ romajify hepburn すし
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Ruby Source Code
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'romajify/converter'
|
44
|
+
puts Romajify::Converter.hepburn('すし')
|
45
|
+
```
|
46
|
+
|
47
|
+
## Supported Romaji
|
48
|
+
|
49
|
+
#### Hepburn Romaji
|
50
|
+
|
51
|
+
Modified Hepburn:
|
52
|
+
|
53
|
+
```sh
|
54
|
+
$ romajify hepburn しんばし
|
55
|
+
# => shinbashi
|
56
|
+
```
|
57
|
+
|
58
|
+
Traditional Hepburn:
|
59
|
+
|
60
|
+
```sh
|
61
|
+
$ romajify hepburn --traditional しんばし
|
62
|
+
# => shimbashi
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Nihon-shiki Romaji
|
66
|
+
|
67
|
+
```sh
|
68
|
+
$ romajify nihon まちづくり
|
69
|
+
# => matidukuri
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Kunrei-shiki Romaji
|
73
|
+
|
74
|
+
```sh
|
75
|
+
$ romajify kunrei まちづくり
|
76
|
+
# => matizukuri
|
77
|
+
```
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/emsk/romajify/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
[MIT](LICENSE.txt)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'romajify'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/romajify
ADDED
data/lib/romajify.rb
ADDED
data/lib/romajify/cli.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'romajify/converter'
|
3
|
+
|
4
|
+
# Japanese romanization library
|
5
|
+
module Romajify
|
6
|
+
|
7
|
+
# Command-line interface of {Romajify}
|
8
|
+
class CLI < Thor
|
9
|
+
class_option :upcase, type: :boolean, aliases: '-u'
|
10
|
+
|
11
|
+
desc 'hepburn KANA', 'Convert kana to Hepburn romaji'
|
12
|
+
option :traditional, type: :boolean, aliases: '-t'
|
13
|
+
|
14
|
+
# Convert kana to Hepburn romaji
|
15
|
+
#
|
16
|
+
# @param text [String] Kana text
|
17
|
+
def hepburn(text)
|
18
|
+
puts Converter.hepburn(text, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'nihon KANA', 'Convert kana to Nihon-shiki romaji'
|
22
|
+
|
23
|
+
# Convert kana to Nihon-shiki romaji
|
24
|
+
#
|
25
|
+
# @param text [String] Kana text
|
26
|
+
def nihon(text)
|
27
|
+
puts Converter.nihon(text, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'kunrei KANA', 'Convert kana to Kunrei-shiki romaji'
|
31
|
+
|
32
|
+
# Convert kana to Kunrei-shiki romaji
|
33
|
+
#
|
34
|
+
# @param text [String] Kana text
|
35
|
+
def kunrei(text)
|
36
|
+
puts Converter.kunrei(text, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc '-v, --version', 'Print the version'
|
40
|
+
map %w(-v --version) => :version
|
41
|
+
|
42
|
+
# Print the version
|
43
|
+
def version
|
44
|
+
puts "romajify #{Romajify::VERSION}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
CLI.start
|
49
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Romajify
|
4
|
+
|
5
|
+
# Class to convert kana to romaji
|
6
|
+
class Converter
|
7
|
+
MONOGRAPHS = {
|
8
|
+
あ: 'a', い: 'i', う: 'u', え: 'e', お: 'o',
|
9
|
+
ア: 'a', イ: 'i', ウ: 'u', エ: 'e', オ: 'o',
|
10
|
+
|
11
|
+
か: 'ka', き: 'ki', く: 'ku', け: 'ke', こ: 'ko',
|
12
|
+
カ: 'ka', キ: 'ki', ク: 'ku', ケ: 'ke', コ: 'ko',
|
13
|
+
|
14
|
+
が: 'ga', ぎ: 'gi', ぐ: 'gu', げ: 'ge', ご: 'go',
|
15
|
+
ガ: 'ga', ギ: 'gi', グ: 'gu', ゲ: 'ge', ゴ: 'go',
|
16
|
+
|
17
|
+
さ: 'sa', し: 'shi', す: 'su', せ: 'se', そ: 'so',
|
18
|
+
サ: 'sa', シ: 'shi', ス: 'su', セ: 'se', ソ: 'so',
|
19
|
+
|
20
|
+
ざ: 'za', じ: 'ji', ず: 'zu', ぜ: 'ze', ぞ: 'zo',
|
21
|
+
ザ: 'za', ジ: 'ji', ズ: 'zu', ゼ: 'ze', ゾ: 'zo',
|
22
|
+
|
23
|
+
た: 'ta', ち: 'chi', つ: 'tsu', て: 'te', と: 'to',
|
24
|
+
タ: 'ta', チ: 'chi', ツ: 'tsu', テ: 'te', ト: 'to',
|
25
|
+
|
26
|
+
だ: 'da', ぢ: 'ji', づ: 'zu', で: 'de', ど: 'do',
|
27
|
+
ダ: 'da', ヂ: 'ji', ヅ: 'zu', デ: 'de', ド: 'do',
|
28
|
+
|
29
|
+
な: 'na', に: 'ni', ぬ: 'nu', ね: 'ne', の: 'no',
|
30
|
+
ナ: 'na', ニ: 'ni', ヌ: 'nu', ネ: 'ne', ノ: 'no',
|
31
|
+
|
32
|
+
は: 'ha', ひ: 'hi', ふ: 'fu', へ: 'he', ほ: 'ho',
|
33
|
+
ハ: 'ha', ヒ: 'hi', フ: 'fu', ヘ: 'he', ホ: 'ho',
|
34
|
+
|
35
|
+
ば: 'ba', び: 'bi', ぶ: 'bu', べ: 'be', ぼ: 'bo',
|
36
|
+
バ: 'ba', ビ: 'bi', ブ: 'bu', ベ: 'be', ボ: 'bo',
|
37
|
+
|
38
|
+
ぱ: 'pa', ぴ: 'pi', ぷ: 'pu', ぺ: 'pe', ぽ: 'po',
|
39
|
+
パ: 'pa', ピ: 'pi', プ: 'pu', ペ: 'pe', ポ: 'po',
|
40
|
+
|
41
|
+
ま: 'ma', み: 'mi', む: 'mu', め: 'me', も: 'mo',
|
42
|
+
マ: 'ma', ミ: 'mi', ム: 'mu', メ: 'me', モ: 'mo',
|
43
|
+
|
44
|
+
や: 'ya', ゆ: 'yu', よ: 'yo',
|
45
|
+
ヤ: 'ya', ユ: 'yu', ヨ: 'yo',
|
46
|
+
|
47
|
+
ら: 'ra', り: 'ri', る: 'ru', れ: 're', ろ: 'ro',
|
48
|
+
ラ: 'ra', リ: 'ri', ル: 'ru', レ: 're', ロ: 'ro',
|
49
|
+
|
50
|
+
わ: 'wa', ゐ: 'i', ゑ: 'e', を: 'o', ん: 'n',
|
51
|
+
ワ: 'wa', ヰ: 'i', ヱ: 'e', ヲ: 'o', ン: 'n',
|
52
|
+
|
53
|
+
ぁ: 'a', ぃ: 'i', ぅ: 'u', ぇ: 'e', ぉ: 'o',
|
54
|
+
ァ: 'a', ィ: 'i', ゥ: 'u', ェ: 'e', ォ: 'o',
|
55
|
+
|
56
|
+
ゃ: 'ya', ゅ: 'yu', ょ: 'yo',
|
57
|
+
ャ: 'ya', ュ: 'yu', ョ: 'yo',
|
58
|
+
|
59
|
+
ゔ: 'bu', ヴ: 'bu', ー: '', _: '_'
|
60
|
+
}
|
61
|
+
|
62
|
+
DIGRAPHS = {
|
63
|
+
きゃ: 'kya', きゅ: 'kyu', きょ: 'kyo',
|
64
|
+
キャ: 'kya', キュ: 'kyu', キョ: 'kyo',
|
65
|
+
|
66
|
+
ぎゃ: 'gya', ぎゅ: 'gyu', ぎょ: 'gyo',
|
67
|
+
ギャ: 'gya', ギュ: 'gyu', ギョ: 'gyo',
|
68
|
+
|
69
|
+
しゃ: 'sha', しゅ: 'shu', しょ: 'sho',
|
70
|
+
シャ: 'sha', シュ: 'shu', ショ: 'sho',
|
71
|
+
|
72
|
+
じゃ: 'ja', じゅ: 'ju', じょ: 'jo',
|
73
|
+
ジャ: 'ja', ジュ: 'ju', ジョ: 'jo',
|
74
|
+
|
75
|
+
ちゃ: 'cha', ちゅ: 'chu', ちょ: 'cho',
|
76
|
+
チャ: 'cha', チュ: 'chu', チョ: 'cho',
|
77
|
+
|
78
|
+
ぢゃ: 'ja', ぢゅ: 'ju', ぢょ: 'jo',
|
79
|
+
ヂャ: 'ja', ヂュ: 'ju', ヂョ: 'jo',
|
80
|
+
|
81
|
+
にゃ: 'nya', にゅ: 'nyu', にょ: 'nyo',
|
82
|
+
ニャ: 'nya', ニュ: 'nyu', ニョ: 'nyo',
|
83
|
+
|
84
|
+
ひゃ: 'hya', ひゅ: 'hyu', ひょ: 'hyo',
|
85
|
+
ヒャ: 'hya', ヒュ: 'hyu', ヒョ: 'hyo',
|
86
|
+
|
87
|
+
びゃ: 'bya', びゅ: 'byu', びょ: 'byo',
|
88
|
+
ビャ: 'bya', ビュ: 'byu', ビョ: 'byo',
|
89
|
+
|
90
|
+
ぴゃ: 'pya', ぴゅ: 'pyu', ぴょ: 'pyo',
|
91
|
+
ピャ: 'pya', ピュ: 'pyu', ピョ: 'pyo',
|
92
|
+
|
93
|
+
みゃ: 'mya', みゅ: 'myu', みょ: 'myo',
|
94
|
+
ミャ: 'mya', ミュ: 'myu', ミョ: 'myo',
|
95
|
+
|
96
|
+
りゃ: 'rya', りゅ: 'ryu', りょ: 'ryo',
|
97
|
+
リャ: 'rya', リュ: 'ryu', リョ: 'ryo'
|
98
|
+
}
|
99
|
+
|
100
|
+
NIHON_MONOGRAPHS = {
|
101
|
+
し: 'si', ち: 'ti', つ: 'tu', ふ: 'hu', じ: 'zi', ぢ: 'di', づ: 'du',
|
102
|
+
シ: 'si', チ: 'ti', ツ: 'tu', フ: 'hu', ジ: 'zi', ヂ: 'di', ヅ: 'du',
|
103
|
+
|
104
|
+
ゐ: 'wi', ゑ: 'we', を: 'wo',
|
105
|
+
ヰ: 'wi', ヱ: 'we', ヲ: 'wo'
|
106
|
+
}
|
107
|
+
|
108
|
+
NIHON_DIGRAPHS = {
|
109
|
+
しゃ: 'sya', しゅ: 'syu', しょ: 'syo',
|
110
|
+
シャ: 'sya', シュ: 'syu', ショ: 'syo',
|
111
|
+
|
112
|
+
じゃ: 'zya', じゅ: 'zyu', じょ: 'zyo',
|
113
|
+
ジャ: 'zya', ジュ: 'zyu', ジョ: 'zyo',
|
114
|
+
|
115
|
+
ちゃ: 'tya', ちゅ: 'tyu', ちょ: 'tyo',
|
116
|
+
チャ: 'tya', チュ: 'tyu', チョ: 'tyo',
|
117
|
+
|
118
|
+
ぢゃ: 'dya', ぢゅ: 'dyu', ぢょ: 'dyo',
|
119
|
+
ヂャ: 'dya', ヂュ: 'dyu', ヂョ: 'dyo'
|
120
|
+
}
|
121
|
+
|
122
|
+
KUNREI_MONOGRAPHS = {
|
123
|
+
し: 'si', ち: 'ti', つ: 'tu', ふ: 'hu', じ: 'zi', ぢ: 'zi',
|
124
|
+
シ: 'si', チ: 'ti', ツ: 'tu', フ: 'hu', ジ: 'zi', ヂ: 'zi'
|
125
|
+
}
|
126
|
+
|
127
|
+
KUNREI_DIGRAPHS = {
|
128
|
+
しゃ: 'sya', しゅ: 'syu', しょ: 'syo',
|
129
|
+
シャ: 'sya', シュ: 'syu', ショ: 'syo',
|
130
|
+
|
131
|
+
じゃ: 'zya', じゅ: 'zyu', じょ: 'zyo',
|
132
|
+
ジャ: 'zya', ジュ: 'zyu', ジョ: 'zyo',
|
133
|
+
|
134
|
+
ちゃ: 'tya', ちゅ: 'tyu', ちょ: 'tyo',
|
135
|
+
チャ: 'tya', チュ: 'tyu', チョ: 'tyo',
|
136
|
+
|
137
|
+
ぢゃ: 'zya', ぢゅ: 'zyu', ぢょ: 'zyo',
|
138
|
+
ヂャ: 'zya', ヂュ: 'zyu', ヂョ: 'zyo'
|
139
|
+
}
|
140
|
+
|
141
|
+
# Convert kana to Hepburn romaji
|
142
|
+
#
|
143
|
+
# @param text [String] Kana text
|
144
|
+
# @param options [Hash] Options
|
145
|
+
# @option options [Boolean] :upcase Whether to return upper case
|
146
|
+
# @option options [Boolean] :traditional Whether to convert to traditional hepburn
|
147
|
+
# @return [String] Romaji text
|
148
|
+
def self.hepburn(text, options = {})
|
149
|
+
result_text = text.dup
|
150
|
+
result_text.encode!(Encoding::UTF_8)
|
151
|
+
|
152
|
+
result_text = romanize(result_text, DIGRAPHS)
|
153
|
+
result_text = romanize(result_text, MONOGRAPHS)
|
154
|
+
|
155
|
+
# Double consonants: 促音
|
156
|
+
result_text.gsub!(/[っッ]c/, 'tc')
|
157
|
+
result_text.gsub!(/[っッ](.)/, '\1\1')
|
158
|
+
|
159
|
+
# Syllabic n: 撥音
|
160
|
+
result_text.gsub!(/n([bmp])/, 'm\1') if options[:traditional]
|
161
|
+
|
162
|
+
# Long vowels: 長音
|
163
|
+
result_text.gsub!(/oo(.+)/, 'o\1')
|
164
|
+
result_text.gsub!(/ou/, 'o')
|
165
|
+
result_text.gsub!(/uu/, 'u')
|
166
|
+
|
167
|
+
result_text.upcase! if options[:upcase]
|
168
|
+
|
169
|
+
result_text
|
170
|
+
end
|
171
|
+
|
172
|
+
# Convert kana to Nihon-shiki romaji
|
173
|
+
#
|
174
|
+
# @param text [String] Kana text
|
175
|
+
# @param options [Hash] Options
|
176
|
+
# @option options [Boolean] :upcase Whether to return upper case
|
177
|
+
# @return [String] Romaji text
|
178
|
+
def self.nihon(text, options = {})
|
179
|
+
result_text = text.dup
|
180
|
+
result_text.encode!(Encoding::UTF_8)
|
181
|
+
|
182
|
+
result_text = romanize(result_text, DIGRAPHS.merge(NIHON_DIGRAPHS))
|
183
|
+
result_text = romanize(result_text, MONOGRAPHS.merge(NIHON_MONOGRAPHS))
|
184
|
+
|
185
|
+
# Double consonants: 促音
|
186
|
+
result_text.gsub!(/[っッ](.)/, '\1\1')
|
187
|
+
|
188
|
+
# Long vowels: 長音
|
189
|
+
result_text.gsub!(/ou|oo/, 'o')
|
190
|
+
result_text.gsub!(/uu/, 'u')
|
191
|
+
|
192
|
+
result_text.upcase! if options[:upcase]
|
193
|
+
|
194
|
+
result_text
|
195
|
+
end
|
196
|
+
|
197
|
+
# Convert kana to Kunrei-shiki romaji
|
198
|
+
#
|
199
|
+
# @param text [String] Kana text
|
200
|
+
# @param options [Hash] Options
|
201
|
+
# @option options [Boolean] :upcase Whether to return upper case
|
202
|
+
# @return [String] Romaji text
|
203
|
+
def self.kunrei(text, options = {})
|
204
|
+
result_text = text.dup
|
205
|
+
result_text.encode!(Encoding::UTF_8)
|
206
|
+
|
207
|
+
result_text = romanize(result_text, DIGRAPHS.merge(KUNREI_DIGRAPHS))
|
208
|
+
result_text = romanize(result_text, MONOGRAPHS.merge(KUNREI_MONOGRAPHS))
|
209
|
+
|
210
|
+
# Double consonants: 促音
|
211
|
+
result_text.gsub!(/[っッ](.)/, '\1\1')
|
212
|
+
|
213
|
+
# Long vowels: 長音
|
214
|
+
result_text.gsub!(/ou|oo/, 'o')
|
215
|
+
result_text.gsub!(/uu/, 'u')
|
216
|
+
|
217
|
+
result_text.upcase! if options[:upcase]
|
218
|
+
|
219
|
+
result_text
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.romanize(text, chars)
|
223
|
+
result_text = text.dup
|
224
|
+
|
225
|
+
chars.each do |kana, romaji|
|
226
|
+
result_text.gsub!(/#{kana}/, romaji)
|
227
|
+
end
|
228
|
+
|
229
|
+
result_text
|
230
|
+
end
|
231
|
+
|
232
|
+
private_class_method :romanize
|
233
|
+
end
|
234
|
+
end
|
data/romajify.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'romajify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'romajify'
|
8
|
+
spec.version = Romajify::VERSION
|
9
|
+
spec.authors = ['emsk']
|
10
|
+
spec.email = ['emsk1987@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Japanese romanization library for Ruby.}
|
13
|
+
spec.description = %q{A Ruby library for converting Japanese Kana to Roman alphabet.}
|
14
|
+
spec.homepage = 'https://github.com/emsk/romajify'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.11'
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
28
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
29
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.38'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: romajify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- emsk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redcarpet
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.38'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.38'
|
139
|
+
description: A Ruby library for converting Japanese Kana to Roman alphabet.
|
140
|
+
email:
|
141
|
+
- emsk1987@gmail.com
|
142
|
+
executables:
|
143
|
+
- romajify
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".coveralls.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".rubocop.yml"
|
151
|
+
- ".travis.yml"
|
152
|
+
- ".yardopts"
|
153
|
+
- Gemfile
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/console
|
158
|
+
- bin/setup
|
159
|
+
- exe/romajify
|
160
|
+
- lib/romajify.rb
|
161
|
+
- lib/romajify/cli.rb
|
162
|
+
- lib/romajify/converter.rb
|
163
|
+
- lib/romajify/version.rb
|
164
|
+
- romajify.gemspec
|
165
|
+
homepage: https://github.com/emsk/romajify
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.5.1
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Japanese romanization library for Ruby.
|
189
|
+
test_files: []
|
190
|
+
has_rdoc:
|