namae2romaji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7d9a31d463660f4569697b8dd0ce31b6c9383db035bcbde02812218c73a9c3b
4
+ data.tar.gz: 49d507a863ce537e67f0bb209d37746e86dfcbdecea600a826f840c854d9dce8
5
+ SHA512:
6
+ metadata.gz: fc3f46faab6e71d05a914c692df285f6ec26a9c6dcc91a3db7524f764e6a5047a4fb948d4cf2b2bce27ea3e75a5f489c168beb29dc22cccbd051fa02cc109504
7
+ data.tar.gz: 7b8f418f626eab6566a0b66e0c9e0cd7dc74d5868cb5b5111e45d3982853c7ce2c379bc40751e50afd3843bc8f412dc1d8f2be521d846c6a804a39b85154177e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nodai2h.itc@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in namae2romaji.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 nodai2hITC
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.
@@ -0,0 +1,77 @@
1
+ # Namae2Romaji
2
+
3
+ Convert Japanese Kana Name to Romaji based on passport regulations.
4
+
5
+ (どうせ日本人以外は使わないので以下日本語で書きます。)
6
+
7
+ ひらがな・カタカナで与えられた氏名文字列を[パスポートにおけるローマ字つづり](https://www.ezairyu.mofa.go.jp/passport/hebon.html)にできるだけ従ってローマ字に変換します。
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'namae2romaji'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install namae2romaji
24
+
25
+ ## Usage
26
+
27
+ 以下のように ```Namae2Romaji.convert(namae)``` メソッドで、ひらがな・カタカナの氏名をローマ字に変換します。最初のスペース(半角・全角どちらでも可)の前・後を名字・名前として、デフォルトでは「名字(すべて大文字) 名前(先頭のみ大文字)」という形でローマ字にします。
28
+
29
+ ```ruby
30
+ require "namae2romaji"
31
+
32
+ # 通常の使い方
33
+ Namae2Romaji.convert("たなか いちろう") # => "TANAKA Ichiro"
34
+
35
+ # 「oう」と(末尾以外の)「oお」を「oh」に変換する
36
+ Namae2Romaji.convert("たなか いちろう", oh: true) # => "TANAKA Ichiroh"
37
+
38
+ # 「名前 名字」の順にする
39
+ Namae2Romaji.convert("たなか いちろう", family_name_first: false) # => "Ichiro Tanaka"
40
+ ```
41
+
42
+ パスポートにおけるローマ字規則に従い、以下のように変換します。
43
+
44
+ - 「ん」は通常は『n』に変換しますが、b,m,p の前では『m』に変換します。
45
+ - 「なんば」=>『namba』
46
+ - 「っ」は通常は後ろの子音を重ねますが、c の前では『t』に変換します。
47
+ - 「はっとり」=>『hattori』、「ほっち」=>『hotchi』
48
+ - 「oお」「oう」「uう」といった長音の「お・う」は、『o,u』には変換しません。
49
+ - 「おおの」=>『ono』、「こうた」=>『kota』、「ひゅうが」=>『hyuga』
50
+ - ただし末尾の「oお」については、「お」を『o』に変換します。
51
+ - 「たかとお」=>『takatoo』
52
+
53
+ ただし、以下のような名前には現状対応していません。
54
+
55
+ - 長音ではない「oお」「oう」「uう」
56
+ - 「こうちわ(小団扇)」「まつうら(松浦)」は、正しくは『kouchiwa』『matsuura』になるべきですが、『kochiwa』『matsura』になってしまいます。
57
+ - 「oお」についてはある程度は対応できています。(例:「ひろおか(広岡)」→『hirooka』)
58
+ - 対処療法としては、「まつ-うら」のようにハイフンを入れておくことで『matsuura』に変換できます。
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/namae2romaji. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/namae2romaji/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+
75
+ ## Code of Conduct
76
+
77
+ Everyone interacting in the Namae2romaji project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/namae2romaji/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "namae2romaji"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require_relative "namae2romaji/to_romaji"
2
+ require_relative "namae2romaji/version"
3
+
4
+ module Namae2Romaji
5
+ def self.convert(namae, oh: false, family_name_first: true)
6
+ romaji = kana_to_romaji(namae.tr(" ", " "), oh: oh)
7
+ fn, gn = romaji.split(" ", 2)
8
+
9
+ return fn.upcase unless gn
10
+ family_name_first ? "#{fn.upcase} #{gn.capitalize}" : "#{gn.capitalize} #{fn.capitalize}"
11
+ end
12
+ end
@@ -0,0 +1,177 @@
1
+ module Namae2Romaji
2
+ ConversionTable = {
3
+ "ア" => "a",
4
+ "イ" => "i",
5
+ "ウ" => "u",
6
+ "エ" => "e",
7
+ "オ" => "o",
8
+
9
+ "カ" => "ka",
10
+ "キ" => "ki",
11
+ "ク" => "ku",
12
+ "ケ" => "ke",
13
+ "コ" => "ko",
14
+
15
+ "サ" => "sa",
16
+ "シ" => "shi",
17
+ "ス" => "su",
18
+ "セ" => "se",
19
+ "ソ" => "so",
20
+
21
+ "タ" => "ta",
22
+ "チ" => "chi",
23
+ "ツ" => "tsu",
24
+ "テ" => "te",
25
+ "ト" => "to",
26
+
27
+ "ナ" => "na",
28
+ "ニ" => "ni",
29
+ "ヌ" => "nu",
30
+ "ネ" => "ne",
31
+ "ノ" => "no",
32
+
33
+ "ハ" => "ha",
34
+ "ヒ" => "hi",
35
+ "フ" => "fu",
36
+ "ヘ" => "he",
37
+ "ホ" => "ho",
38
+
39
+ "マ" => "ma",
40
+ "ミ" => "mi",
41
+ "ム" => "mu",
42
+ "メ" => "me",
43
+ "モ" => "mo",
44
+
45
+ "ヤ" => "ya",
46
+ "ユ" => "yu",
47
+ "ヨ" => "yo",
48
+
49
+ "ラ" => "ra",
50
+ "リ" => "ri",
51
+ "ル" => "ru",
52
+ "レ" => "re",
53
+ "ロ" => "ro",
54
+
55
+ "ワ" => "wa",
56
+ "ヰ" => "i",
57
+ "ヱ" => "e",
58
+ "ヲ" => "o",
59
+ "ン" => "n",
60
+
61
+ "ガ" => "ga",
62
+ "ギ" => "gi",
63
+ "グ" => "gu",
64
+ "ゲ" => "ge",
65
+ "ゴ" => "go",
66
+
67
+ "ザ" => "za",
68
+ "ジ" => "ji",
69
+ "ズ" => "zu",
70
+ "ゼ" => "ze",
71
+ "ゾ" => "zo",
72
+
73
+ "ダ" => "da",
74
+ "ヂ" => "ji",
75
+ "ヅ" => "zu",
76
+ "デ" => "de",
77
+ "ド" => "do",
78
+
79
+ "バ" => "ba",
80
+ "ビ" => "bi",
81
+ "ブ" => "bu",
82
+ "ベ" => "be",
83
+ "ボ" => "bo",
84
+
85
+ "パ" => "pa",
86
+ "ピ" => "pi",
87
+ "プ" => "pu",
88
+ "ペ" => "pe",
89
+ "ポ" => "po",
90
+
91
+ "キャ" => "kya",
92
+ "キュ" => "kyu",
93
+ "キョ" => "kyo",
94
+
95
+ "シャ" => "sha",
96
+ "シュ" => "shu",
97
+ "ショ" => "sho",
98
+
99
+ "チャ" => "cha",
100
+ "チュ" => "chu",
101
+ "チョ" => "cho",
102
+
103
+ "ニャ" => "nya",
104
+ "ニュ" => "nyu",
105
+ "ニョ" => "nyo",
106
+
107
+ "ヒャ" => "hya",
108
+ "ヒュ" => "hyu",
109
+ "ヒョ" => "hyo",
110
+
111
+ "ミャ" => "mya",
112
+ "ミュ" => "myu",
113
+ "ミョ" => "myo",
114
+
115
+ "リャ" => "rya",
116
+ "リュ" => "ryu",
117
+ "リョ" => "ryo",
118
+
119
+ "ギャ" => "gya",
120
+ "ギュ" => "gyu",
121
+ "ギョ" => "gyo",
122
+
123
+ "ジャ" => "ja",
124
+ "ジュ" => "ju",
125
+ "ジョ" => "jo",
126
+
127
+ "ビャ" => "bya",
128
+ "ビュ" => "byu",
129
+ "ビョ" => "byo",
130
+
131
+ "ピャ" => "pya",
132
+ "ピュ" => "pyu",
133
+ "ピョ" => "pyo",
134
+
135
+ "シェ" => "shie",
136
+ "チェ" => "chie",
137
+ "ティ" => "tei",
138
+ "ニィ" => "nii",
139
+ "ニェ" => "nie",
140
+
141
+ "ファ" => "fua",
142
+ "フィ" => "fui",
143
+ "フェ" => "fue",
144
+ "フォ" => "fuo",
145
+ "ジェ" => "jie",
146
+
147
+ "ディ" => "dei",
148
+ "デュ" => "deyu",
149
+ "ウィ" => "ui",
150
+ "ウェ" => "ue",
151
+ "ウォ" => "uo",
152
+
153
+ "ヴァ" => "ba",
154
+ "ヴィ" => "bi",
155
+ "ヴ" => "bu",
156
+ "ヴェ" => "be",
157
+ "ヴォ" => "bo",
158
+
159
+ "ー" => "",
160
+ "-" => "",
161
+ "-" => "",
162
+
163
+ "ッ" => "ッ"
164
+ }
165
+
166
+ def self.kana_to_romaji(kana, oh: false)
167
+ kana = kana.encode(Encoding::UTF_8)
168
+ .tr('ぁ-ゔ','ァ-ヴ')
169
+ .gsub(/(?<=[オコソトノホモヨロヲゴゾドボポョォ])オ\z/, "o")
170
+ .gsub(/(?<=[オト])オ/, oh ? "h" : "")
171
+ .gsub(/(?<=[オコソトノホモヨロヲゴゾドボポョォ])ウ/, oh ? "h" : "")
172
+ .gsub(/(?<=[ウクスツヌフムユルヴグズヅブプュゥ])ウ/, "")
173
+ .gsub(/[ァ-ヴー-\-][ァィゥェォャュョ]?/, ConversionTable)
174
+ .gsub(/ッ(.)/){ ($1 == "c" ? "t" : $1) + $1 }
175
+ .gsub(/n(?=[bmp])/, "m")
176
+ end
177
+ end
@@ -0,0 +1,3 @@
1
+ module Namae2Romaji
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/namae2romaji/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "namae2romaji"
5
+ spec.version = Namae2Romaji::VERSION
6
+ spec.authors = ["nodai2hITC"]
7
+ spec.email = ["nodai2h.itc@gmail.com"]
8
+
9
+ spec.summary = %q{Convert Japanese Kana Name to Romaji}
10
+ spec.description = %q{Convert Japanese Kana Name to Romaji based on passport regulations.}
11
+ spec.homepage = "https://github.com/nodai2hITC/namae2romaji"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namae2romaji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nodai2hITC
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Convert Japanese Kana Name to Romaji based on passport regulations.
14
+ email:
15
+ - nodai2h.itc@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/namae2romaji.rb
30
+ - lib/namae2romaji/to_romaji.rb
31
+ - lib/namae2romaji/version.rb
32
+ - namae2romaji.gemspec
33
+ homepage: https://github.com/nodai2hITC/namae2romaji
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/nodai2hITC/namae2romaji
38
+ source_code_uri: https://github.com/nodai2hITC/namae2romaji
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.1.2
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Convert Japanese Kana Name to Romaji
58
+ test_files: []