jp_prefecture 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/jp_prefecture/prefecture.rb +3 -2
- data/lib/jp_prefecture/version.rb +1 -1
- data/spec/prefecture_spec.rb +62 -34
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -94,9 +94,10 @@ module JpPrefecture
|
|
94
94
|
|
95
95
|
# 名前から都道府県コードを検索
|
96
96
|
def self.find_code_by_name(name)
|
97
|
-
|
97
|
+
result = PREFECTURE_CODE_NAME.select { |_, v|
|
98
|
+
v.has_value?(name.capitalize)
|
99
|
+
}.first
|
98
100
|
|
99
|
-
result = PREFECTURE_CODE_NAME.select { |_, v| v.has_value?(name) }.first
|
100
101
|
return if result.nil?
|
101
102
|
|
102
103
|
result[0]
|
data/spec/prefecture_spec.rb
CHANGED
@@ -10,47 +10,75 @@ describe JpPrefecture::Prefecture do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.find' do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
describe '検索結果について' do
|
14
|
+
shared_examples "都道府県が見つかる" do |arg|
|
15
|
+
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
16
|
+
it { pref.code.should eq 1 }
|
17
|
+
it { pref.name.should eq '北海道' }
|
18
|
+
it { pref.name_e.should eq 'Hokkaido' }
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
shared_examples '都道府県が見つからない' do |arg|
|
22
|
+
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
23
|
+
it { pref.should be_nil }
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
describe '都道府県コード' do
|
27
|
+
it_behaves_like "都道府県が見つかる", 1
|
28
|
+
it_behaves_like "都道府県が見つからない", 99
|
29
|
+
it_behaves_like "都道府県が見つかる", "1"
|
30
|
+
it_behaves_like "都道府県が見つかる", "01"
|
31
|
+
it_behaves_like "都道府県が見つからない", "99"
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
describe '都道府県コード(キーワード引数)' do
|
35
|
+
it_behaves_like "都道府県が見つかる", code: 1
|
36
|
+
it_behaves_like "都道府県が見つからない", code: 99
|
37
|
+
it_behaves_like "都道府県が見つかる", code: "1"
|
38
|
+
it_behaves_like "都道府県が見つかる", code: "01"
|
39
|
+
it_behaves_like "都道府県が見つからない", code: "99"
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
describe '都道府県名' do
|
43
|
+
it_behaves_like "都道府県が見つかる", name: "北海道"
|
44
|
+
it_behaves_like "都道府県が見つからない", name: "うどん県"
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '都道府県名(英語表記)' do
|
48
|
+
it_behaves_like "都道府県が見つかる", name: "Hokkaido"
|
49
|
+
it_behaves_like "都道府県が見つからない", name: "Udon"
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
describe '都道府県名(英語表記-小文字)' do
|
53
|
+
it_behaves_like "都道府県が見つかる", name: "hokkaido"
|
54
|
+
it_behaves_like "都道府県が見つからない", name: "udon"
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
|
-
describe '
|
52
|
-
|
53
|
-
|
58
|
+
describe '渡した変数について' do
|
59
|
+
context 'string の場合' do
|
60
|
+
it '値が変更されないこと' do
|
61
|
+
code = '1'
|
62
|
+
JpPrefecture::Prefecture.find(code)
|
63
|
+
code.should eq '1'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'code が string の場合' do
|
68
|
+
it '値が変更されないこと' do
|
69
|
+
code = '1'
|
70
|
+
JpPrefecture::Prefecture.find(code: code)
|
71
|
+
code.should eq '1'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'name の場合' do
|
76
|
+
it '値が変更されないこと' do
|
77
|
+
name = 'hokkaido'
|
78
|
+
JpPrefecture::Prefecture.find(name: name)
|
79
|
+
name.should eq 'hokkaido'
|
80
|
+
end
|
81
|
+
end
|
54
82
|
end
|
55
83
|
end
|
56
84
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jp_prefecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|