kanalphabet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/kanalphabet.gemspec +26 -0
- data/lib/kanalphabet.rb +7 -0
- data/lib/kanalphabet/constants.rb +72 -0
- data/lib/kanalphabet/core.rb +32 -0
- data/lib/kanalphabet/core_ext/string.rb +15 -0
- data/lib/kanalphabet/version.rb +3 -0
- data/spec/kanalphabet_spec.rb +37 -0
- data/spec/spec_helper.rb +0 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16098c10690d46b8d69030ff801cd69fd59ed1b9
|
4
|
+
data.tar.gz: 968ae74d74497ae8736df3b51869c5fecc000b4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b3e70cf0f07494f92e0427687b9fff3fc4e0ac5256aa65f1d35a6ee6ea6b88f403551f4b9033b5696a45560288967009edef9851486220224705844bb5f2b72
|
7
|
+
data.tar.gz: 60cc5842f9407acd7c256a6a88f6ef15e14c3b8f5b3ac9158deab5615617b9fda99745bbb87424df73b18f85e73ee87e1d08056285729781268f741a8a355499
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yamitzky
|
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,49 @@
|
|
1
|
+
# Kanalphabet
|
2
|
+
|
3
|
+
This gem is a converter kana <-> alphabet, following a pronunciation of alphabet, not romaji.
|
4
|
+
|
5
|
+
e.g. エー <-> A, エー <-> A, えー <-> A
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'kanalphabet'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kanalphabet
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
require 'kanalphabet'
|
24
|
+
kana = "エー"
|
25
|
+
alphabet = kana.to_alphabet # A
|
26
|
+
alphabet.to_hiragana # えー
|
27
|
+
alphabet.to_katakana # エー
|
28
|
+
|
29
|
+
## Future work
|
30
|
+
|
31
|
+
**Not** implemented yet. Someday, someone will implement them.
|
32
|
+
|
33
|
+
require 'kanalphabet'
|
34
|
+
"エルオーブイイー".to_alphabet # LOVE
|
35
|
+
"SFC".to_hiragana join_by: "・" # エス・エフ・シー
|
36
|
+
"A".to_hankaku # エー
|
37
|
+
|
38
|
+
converter = Kanalphabet::Converter.new(A: "エイ")
|
39
|
+
converter.to_hiragana("ABC") # エイビーシー
|
40
|
+
converter = Kanalphabet::Converter.new(ignore: "エッチ")
|
41
|
+
converter.to_alphabet("えっち") # えっち
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/kanalphabet.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kanalphabet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kanalphabet"
|
8
|
+
spec.version = Kanalphabet::VERSION
|
9
|
+
spec.authors = ["Yamitzky"]
|
10
|
+
spec.email = ["negiga@gmail.com"]
|
11
|
+
spec.description = %q{Convert kana and alphabet with following pronunciation of alphabet, not ro-maji}
|
12
|
+
spec.summary = %q{Kana <-> Alphabet Converter}
|
13
|
+
spec.homepage = "https://github.com/yamitzky/kanalphabet"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
end
|
data/lib/kanalphabet.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Kanalphabet
|
4
|
+
KANA_TO_ALPHABET = {
|
5
|
+
"エー" => "A",
|
6
|
+
"エイ" => "A",
|
7
|
+
"ビー" => "B",
|
8
|
+
"シー" => "C",
|
9
|
+
"ディー" => "D",
|
10
|
+
"イー" => "E",
|
11
|
+
"エフ" => "F",
|
12
|
+
"ジー" => "G",
|
13
|
+
"エイチ" => "H",
|
14
|
+
"エッチ" => "H",
|
15
|
+
"アイ" => "I",
|
16
|
+
"ジェイ" => "J",
|
17
|
+
"ジェー" => "J",
|
18
|
+
"ケー" => "K",
|
19
|
+
"ケイ" => "K",
|
20
|
+
"エル" => "L",
|
21
|
+
"エヌ" => "N",
|
22
|
+
"エム" => "M",
|
23
|
+
"オー" => "O",
|
24
|
+
"ピー" => "P",
|
25
|
+
"キュー" => "Q",
|
26
|
+
"アール" => "R",
|
27
|
+
"エス" => "S",
|
28
|
+
"ティー" => "T",
|
29
|
+
"ティ" => "T",
|
30
|
+
"ユー" => "U",
|
31
|
+
"ブイ" => "V",
|
32
|
+
"ヴイ" => "V",
|
33
|
+
"ヴィー" => "V",
|
34
|
+
"ダブリュー" => "W",
|
35
|
+
"ダブリュ" => "W",
|
36
|
+
"ダブル" => "W",
|
37
|
+
"エックス" => "X",
|
38
|
+
"エクス" => "X",
|
39
|
+
"ワイ" => "Y",
|
40
|
+
"ズィー" => "Z",
|
41
|
+
"ゼット" => "Z"
|
42
|
+
}
|
43
|
+
|
44
|
+
ALPHABET_TO_KANA = {
|
45
|
+
"A" => "エー",
|
46
|
+
"B" => "ビー",
|
47
|
+
"C" => "シー",
|
48
|
+
"D" => "ディー",
|
49
|
+
"E" => "イー",
|
50
|
+
"F" => "エフ",
|
51
|
+
"G" => "ジー",
|
52
|
+
"H" => "エイチ",
|
53
|
+
"I" => "アイ",
|
54
|
+
"J" => "ジェイ",
|
55
|
+
"K" => "ケー",
|
56
|
+
"L" => "エル",
|
57
|
+
"N" => "エヌ",
|
58
|
+
"M" => "エム",
|
59
|
+
"O" => "オー",
|
60
|
+
"P" => "ピー",
|
61
|
+
"Q" => "キュー",
|
62
|
+
"R" => "アール",
|
63
|
+
"S" => "エス",
|
64
|
+
"T" => "ティー",
|
65
|
+
"U" => "ユー",
|
66
|
+
"V" => "ブイ",
|
67
|
+
"W" => "ダブル",
|
68
|
+
"X" => "エックス",
|
69
|
+
"Y" => "ワイ",
|
70
|
+
"Z" => "ゼット"
|
71
|
+
}
|
72
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Kanalphabet
|
2
|
+
require "nkf"
|
3
|
+
|
4
|
+
def self.convert_to_alphabet(str)
|
5
|
+
katakana = NKF::nkf("-Ww --katakana", str)
|
6
|
+
alphabet = Kanalphabet::KANA_TO_ALPHABET[katakana]
|
7
|
+
|
8
|
+
if alphabet
|
9
|
+
alphabet
|
10
|
+
else
|
11
|
+
str
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.convert_to_katakana(str)
|
16
|
+
self.to_kana(str, "katakana")
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.convert_to_hiragana(str)
|
20
|
+
self.to_kana(str, "hiragana")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def self.to_kana(str, option)
|
25
|
+
kana = Kanalphabet::ALPHABET_TO_KANA[str.upcase]
|
26
|
+
if kana
|
27
|
+
NKF::nkf("-Ww --#{option}", kana)
|
28
|
+
else
|
29
|
+
str
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "kanalphabet"
|
4
|
+
|
5
|
+
describe String do
|
6
|
+
it "should be converted from all type of kana to alphabet" do
|
7
|
+
"エー".to_alphabet.should == "A"
|
8
|
+
"ビー".to_alphabet.should == "B"
|
9
|
+
"しー".to_alphabet.should == "C"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be converted from shaken kana to alphabet" do
|
13
|
+
"えいち".to_alphabet.should == "H"
|
14
|
+
"えっち".to_alphabet.should == "H"
|
15
|
+
"ヴィー".to_alphabet.should == "V"
|
16
|
+
"ブイ".to_alphabet.should == "V"
|
17
|
+
"ヴい".to_alphabet.should == "V"
|
18
|
+
"ダブル".to_alphabet.should == "W"
|
19
|
+
"だぶりゅー".to_alphabet.should == "W"
|
20
|
+
"ズィー".to_alphabet.should == "Z"
|
21
|
+
"ゼット".to_alphabet.should == "Z"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be converted from alphabet to kana" do
|
25
|
+
"A".to_katakana.should == "エー"
|
26
|
+
"B".to_hiragana.should == "びー"
|
27
|
+
"c".to_katakana.should == "シー"
|
28
|
+
end
|
29
|
+
|
30
|
+
context "not convertable text" do
|
31
|
+
it "should not be changed" do
|
32
|
+
"やみつき".to_alphabet.should == "やみつき"
|
33
|
+
"λ".to_hiragana.should == "λ"
|
34
|
+
"Λ".to_katakana.should == "Λ"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kanalphabet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yamitzky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Convert kana and alphabet with following pronunciation of alphabet, not
|
84
|
+
ro-maji
|
85
|
+
email:
|
86
|
+
- negiga@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- Guardfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- kanalphabet.gemspec
|
98
|
+
- lib/kanalphabet.rb
|
99
|
+
- lib/kanalphabet/constants.rb
|
100
|
+
- lib/kanalphabet/core.rb
|
101
|
+
- lib/kanalphabet/core_ext/string.rb
|
102
|
+
- lib/kanalphabet/version.rb
|
103
|
+
- spec/kanalphabet_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/yamitzky/kanalphabet
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.0.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Kana <-> Alphabet Converter
|
129
|
+
test_files:
|
130
|
+
- spec/kanalphabet_spec.rb
|
131
|
+
- spec/spec_helper.rb
|