pokebell 0.0.2 → 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/Gemfile +2 -0
- data/README.md +18 -5
- data/VERSION +1 -1
- data/lib/pokebell.rb +88 -4
- data/pokebell.gemspec +5 -2
- data/spec/pokebell_spec.rb +62 -2
- data/spec/spec_helper.rb +2 -1
- metadata +19 -3
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# pokebell
|
2
2
|
|
3
|
-
This gem is convert from Japanese message written by Hiragana / Katakana / alphabet / digit to Japanese pager aka "Pokebell" 2-digits format codes.
|
3
|
+
This gem is convert from Japanese message written by Hiragana / Katakana / alphabet / digit to Japanese pager aka "Pokebell" 2-digits format codes, and from the code to Katakana message.
|
4
4
|
|
5
5
|
## usage
|
6
6
|
|
@@ -8,8 +8,15 @@ This gem is convert from Japanese message written by Hiragana / Katakana / alpha
|
|
8
8
|
pokeberu = Pokebell.new("ぽけべる")
|
9
9
|
pokeberu.pokebell #=> "650524640493"
|
10
10
|
pokeberu.code #=> "650524640493"
|
11
|
-
pokeberu.str #=> "
|
12
|
-
pokeberu.
|
11
|
+
pokeberu.str #=> "ポケベル"
|
12
|
+
pokeberu.to_s #=> "ポケベル"
|
13
|
+
```
|
14
|
+
```
|
15
|
+
pokeberu = Pokebell.number("650524640493")
|
16
|
+
pokeberu.pokebell #=> "650524640493"
|
17
|
+
pokeberu.code #=> "650524640493"
|
18
|
+
pokeberu.str #=> "ポケベル"
|
19
|
+
pokeberu.to_s #=> "ポケベル"
|
13
20
|
```
|
14
21
|
|
15
22
|
## convert table
|
@@ -53,12 +60,18 @@ Pokebell.new("ruby").pokebell #=> "48561750"
|
|
53
60
|
Pokebell.new("hello pokebell").pokebell
|
54
61
|
#=> "2810373730884630361017103737"
|
55
62
|
```
|
56
|
-
|
63
|
+
```
|
64
|
+
Pokebell.number("61056993").str #=> "パール"
|
65
|
+
Pokebell.number("93620469").str #=> "ルビー"
|
66
|
+
Pokebell.number("46104837").str #=> "PERL"
|
67
|
+
Pokebell.number("48561750").str #=> "RUBY"
|
68
|
+
Pokebell.number("2810373730884630361017103737").str
|
69
|
+
#=> "HELLO POKEBELL"
|
70
|
+
```
|
57
71
|
##TODO
|
58
72
|
|
59
73
|
* RSpec
|
60
74
|
* Emoji (Clock="78", Phone="79", Cup="70", Heart="89")
|
61
|
-
* Convert (Decode) from codes to Japanese charactors
|
62
75
|
|
63
76
|
## Contributing to pokebell
|
64
77
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/pokebell.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
|
+
|
4
|
+
require 'moji'
|
5
|
+
|
3
6
|
require 'nkf'
|
4
7
|
|
5
8
|
class Pokebell
|
@@ -7,23 +10,82 @@ class Pokebell
|
|
7
10
|
# @param str [String] message (contains Hiragana / Katakana / alphabet / digit)
|
8
11
|
# @return [Pokebell]
|
9
12
|
def initialize(str)
|
10
|
-
@str = str.gsub(/\\/, "")
|
13
|
+
@str = Moji.han_to_zen(hiragana2katakana(str.upcase.gsub(/\\/, "")))
|
11
14
|
@pokebell = pick_hankaku_code(zenkaku2hankaku(@str)).map{ |code| encode(code) }.join
|
12
15
|
end
|
13
16
|
|
17
|
+
# Set Pokebell code and make message string.
|
18
|
+
# @param num [String] Pokebell code (length must be even)
|
19
|
+
# @raise [ArgumentError] if param does not makes digit or its length is not even
|
20
|
+
# @return [Pokebell]
|
21
|
+
# @since 0.1.0
|
22
|
+
def self.number(num)
|
23
|
+
num_str = num.to_s
|
24
|
+
unless num_str == num_str[/(\d\d)+/]
|
25
|
+
raise ArgumentError, "wrong digit length (must be even digits)"
|
26
|
+
end
|
27
|
+
two_digits_array = num_str.scan(/\d\d/)
|
28
|
+
str_array_with_daku_handaku = make_str_array(two_digits_array)
|
29
|
+
str_array = []
|
30
|
+
loop do
|
31
|
+
follow_char = nil
|
32
|
+
char = str_array_with_daku_handaku.shift
|
33
|
+
break unless char
|
34
|
+
follow_char_test = str_array_with_daku_handaku.first
|
35
|
+
unless follow_char_test
|
36
|
+
str_array << char
|
37
|
+
break
|
38
|
+
end
|
39
|
+
if follow_char_test[/[゛゜]/]
|
40
|
+
follow_char = str_array_with_daku_handaku.shift
|
41
|
+
char = merge_daku_handaku(char, follow_char)
|
42
|
+
end
|
43
|
+
str_array << char
|
44
|
+
end
|
45
|
+
str = str_array.join
|
46
|
+
Pokebell.new(str)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String]
|
50
|
+
# @since 0.1.0
|
51
|
+
def inspect
|
52
|
+
%[#<str="#{@str}", pokebell="#{@pokebell}">]
|
53
|
+
end
|
54
|
+
|
14
55
|
# @!method pokebell
|
15
56
|
# @return [String] Pokebell codes (2-digit string)
|
16
57
|
attr_reader :pokebell
|
17
58
|
alias :code :pokebell
|
59
|
+
alias :num :pokebell
|
18
60
|
|
19
61
|
# @!method str
|
20
|
-
# @return [String]
|
62
|
+
# @return [String] message (convert to Zenkaku charactors, especially from Hiragana to Katakana)
|
21
63
|
attr_reader :str
|
22
|
-
alias :
|
64
|
+
alias :to_s :str
|
65
|
+
alias :text :str
|
23
66
|
|
24
67
|
private
|
68
|
+
TABLE = [
|
69
|
+
%w[0 ワ ヲ ン ゛ ゜ 6 7 8 9],
|
70
|
+
%w[E ア イ ウ エ オ A B C D],
|
71
|
+
%w[J カ キ ク ケ コ F G H I],
|
72
|
+
%w[O サ シ ス セ ソ K L M N],
|
73
|
+
%w[T タ チ ツ テ ト P Q R S],
|
74
|
+
%w[Y ナ ニ ヌ ネ ノ U V W X],
|
75
|
+
%w[/ ハ ヒ フ ヘ ホ Z ? ! ー],
|
76
|
+
([""] + %w[マ ミ ム メ モ ¥ &] + ["", ""]),
|
77
|
+
([""] + %w[ヤ ( ユ ) ヨ * # ] + [""]),
|
78
|
+
%w[5 ラ リ ル レ ロ 1 2 3 4],
|
79
|
+
]
|
80
|
+
DAKU_BASE_REGEX = /[カキクケコサシスセソタチツテト]/
|
81
|
+
DAKU_HANDAKU_BASE_REGEX = /[ハヒフヘホ]/
|
82
|
+
|
25
83
|
def zenkaku2hankaku(str)
|
26
|
-
NKF.nkf('-
|
84
|
+
NKF.nkf('-jZ4', str)
|
85
|
+
end
|
86
|
+
|
87
|
+
def hiragana2katakana(str)
|
88
|
+
NKF.nkf("-wh2", str).gsub("¥", "¥")
|
27
89
|
end
|
28
90
|
|
29
91
|
def escape_char?(char)
|
@@ -53,6 +115,8 @@ class Pokebell
|
|
53
115
|
else
|
54
116
|
raise "out of aiming JIS charactor area"
|
55
117
|
end
|
118
|
+
elsif char.unpack("C") == "\x21".unpack("C")
|
119
|
+
|
56
120
|
else
|
57
121
|
raise "out of aiming JIS charactor area"
|
58
122
|
end
|
@@ -157,4 +221,24 @@ class Pokebell
|
|
157
221
|
raise "out of aiming charactor area"
|
158
222
|
end
|
159
223
|
end
|
224
|
+
|
225
|
+
def self.make_str_array(array)
|
226
|
+
array.map { |digits|
|
227
|
+
i = digits[0].to_i
|
228
|
+
j = digits[1].to_i
|
229
|
+
TABLE[i][j]
|
230
|
+
}
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.merge_daku_handaku(char, follow_char)
|
234
|
+
if follow_char[/゛/] && char[Regexp.union(DAKU_BASE_REGEX, DAKU_HANDAKU_BASE_REGEX)]
|
235
|
+
[char.unpack("U*").first + 1].pack("U")
|
236
|
+
elsif follow_char[/゜/] && char[DAKU_HANDAKU_BASE_REGEX]
|
237
|
+
[char.unpack("U*").first + 2].pack("U")
|
238
|
+
elsif follow_char[/゛/] && char[/ウ/]
|
239
|
+
"ヴ"
|
240
|
+
else
|
241
|
+
char + follow_char
|
242
|
+
end
|
243
|
+
end
|
160
244
|
end
|
data/pokebell.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "pokebell"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["riocampos"]
|
12
|
-
s.date = "2014-
|
12
|
+
s.date = "2014-07-29"
|
13
13
|
s.description = "Japanese charactor displayed by hiragana, alphabet, or number encode to 2-digit in used \"Pokebell\" pager."
|
14
14
|
s.email = "riocampos22@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,12 +38,14 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.specification_version = 3
|
39
39
|
|
40
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_runtime_dependency(%q<moji>, ["= 1.6"])
|
41
42
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
42
43
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
43
44
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
44
45
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
45
46
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
46
47
|
else
|
48
|
+
s.add_dependency(%q<moji>, ["= 1.6"])
|
47
49
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
48
50
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
49
51
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
@@ -51,6 +53,7 @@ Gem::Specification.new do |s|
|
|
51
53
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
52
54
|
end
|
53
55
|
else
|
56
|
+
s.add_dependency(%q<moji>, ["= 1.6"])
|
54
57
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
55
58
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
59
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
data/spec/pokebell_spec.rb
CHANGED
@@ -1,7 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
4
|
|
5
|
+
match_hash = {
|
6
|
+
"カキクケコ" => "2122232425",
|
7
|
+
"ガギグゲゴ" => "21042204230424042504",
|
8
|
+
"パピプペポ" => "61056205630564056505",
|
9
|
+
"ヤユヨ" => "818385",
|
10
|
+
"()" => "8284",
|
11
|
+
"ラリルレロ" => "9192939495",
|
12
|
+
"ワヲン" => "010203",
|
13
|
+
"ABCDE" => "1617181910",
|
14
|
+
"Z?!ー/" => "6667686960",
|
15
|
+
"¥&*# " => "7677868788",
|
16
|
+
"1234567890" => "96979899900607080900",
|
17
|
+
"パンガオイシイー" => "61050321041512321269",
|
18
|
+
"ヴアイオリン" => "13041112159203",
|
19
|
+
}
|
20
|
+
|
21
|
+
match_hash1 = match_hash.merge({
|
22
|
+
"あいうえお" => "1112131415",
|
23
|
+
"サシスセソ" => "3132333435",
|
24
|
+
"゛゜" => "0405",
|
25
|
+
"あ゛" => "1104",
|
26
|
+
"バビブベボ" => "61046204630464046504",
|
27
|
+
"67890" => "0607080900",
|
28
|
+
"hello pokebell" => "2810373730884630361017103737",
|
29
|
+
})
|
30
|
+
match_hash2 = match_hash.merge({
|
31
|
+
" ゛ ゜" => "88048805",
|
32
|
+
"バビブベボ" => "61046204630464046504",
|
33
|
+
"67890" => "0607080900",
|
34
|
+
"HELLO POKEBELL" => "2810373730884630361017103737",
|
35
|
+
})
|
36
|
+
|
3
37
|
describe "Pokebell" do
|
4
|
-
|
5
|
-
|
38
|
+
match_hash1.each_pair do |str, num|
|
39
|
+
context %[give string "#{str}"] do
|
40
|
+
it do
|
41
|
+
str_pokebell = Pokebell.new(str)
|
42
|
+
expect(str_pokebell.pokebell).to eq num
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "give number 111" do
|
48
|
+
it 'raise ArgumentError' do
|
49
|
+
expect { Pokebell.number("111") }.to raise_error ArgumentError, "wrong digit length (must be even digits)"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'give number "abc"' do
|
54
|
+
it 'raise ArgumentError' do
|
55
|
+
expect { Pokebell.number("abc") }.to raise_error ArgumentError, "wrong digit length (must be even digits)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
match_hash2.each_pair do |str, num|
|
60
|
+
context %[give number "#{num}"] do
|
61
|
+
it do
|
62
|
+
num_pokebell = Pokebell.number(num)
|
63
|
+
expect(num_pokebell.str).to eq str
|
64
|
+
end
|
65
|
+
end
|
6
66
|
end
|
7
67
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pokebell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: moji
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rspec
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
142
|
version: '0'
|
127
143
|
segments:
|
128
144
|
- 0
|
129
|
-
hash:
|
145
|
+
hash: 2450097076129829719
|
130
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
147
|
none: false
|
132
148
|
requirements:
|