jp_prefecture 0.8.1 → 1.0.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +70 -13
- data/LICENSE +17 -18
- data/README.md +64 -51
- data/README_EN.md +227 -0
- data/data/zip.yml +10 -5
- data/lib/jp_prefecture.rb +6 -5
- data/lib/jp_prefecture/base.rb +3 -2
- data/lib/jp_prefecture/config.rb +2 -4
- data/lib/jp_prefecture/mapping.rb +2 -2
- data/lib/jp_prefecture/prefecture.rb +74 -101
- data/lib/jp_prefecture/prefecture/finder.rb +71 -0
- data/lib/jp_prefecture/version.rb +3 -1
- data/lib/jp_prefecture/zip_mapping.rb +9 -6
- metadata +107 -44
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/.travis.yml +0 -13
- data/.yardopts +0 -2
- data/Gemfile +0 -3
- data/Rakefile +0 -74
- data/jp_prefecture.gemspec +0 -23
- data/spec/base_spec.rb +0 -81
- data/spec/config_spec.rb +0 -18
- data/spec/fixtures/prefecture.yml +0 -148
- data/spec/jp_prefecture_spec.rb +0 -36
- data/spec/mapping_spec.rb +0 -10
- data/spec/prefecture_spec.rb +0 -163
- data/spec/spec_helper.rb +0 -35
- data/spec/zip_mapping_spec.rb +0 -10
data/spec/prefecture_spec.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe JpPrefecture::Prefecture do
|
5
|
-
describe '.build' do
|
6
|
-
let(:pref) { JpPrefecture::Prefecture.build(1, '北海道', 'Hokkaido', 'ほっかいどう', 'ホッカイドウ', '北海道') }
|
7
|
-
it { expect(pref.code).to eq 1 }
|
8
|
-
it { expect(pref.name).to eq '北海道' }
|
9
|
-
it { expect(pref.name_e).to eq 'Hokkaido' }
|
10
|
-
it { expect(pref.name_h).to eq 'ほっかいどう' }
|
11
|
-
it { expect(pref.name_k).to eq 'ホッカイドウ' }
|
12
|
-
it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
|
13
|
-
it { expect(pref.area).to eq '北海道' }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '.find' do
|
17
|
-
describe '検索結果について' do
|
18
|
-
shared_examples "都道府県が見つかる" do |arg|
|
19
|
-
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
20
|
-
it { expect(pref.code).to eq 1 }
|
21
|
-
it { expect(pref.name).to eq '北海道' }
|
22
|
-
it { expect(pref.name_e).to eq 'Hokkaido' }
|
23
|
-
it { expect(pref.name_h).to eq 'ほっかいどう' }
|
24
|
-
it { expect(pref.name_k).to eq 'ホッカイドウ' }
|
25
|
-
it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
|
26
|
-
it { expect(pref.area).to eq '北海道' }
|
27
|
-
end
|
28
|
-
|
29
|
-
shared_examples '都道府県が見つからない' do |arg|
|
30
|
-
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
31
|
-
it { expect(pref).to be_nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '都道府県コード' do
|
35
|
-
it_behaves_like "都道府県が見つかる", 1
|
36
|
-
it_behaves_like "都道府県が見つからない", 99
|
37
|
-
it_behaves_like "都道府県が見つかる", "1"
|
38
|
-
it_behaves_like "都道府県が見つかる", "01"
|
39
|
-
it_behaves_like "都道府県が見つからない", "99"
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '都道府県コード(キーワード引数)' do
|
43
|
-
it_behaves_like "都道府県が見つかる", code: 1
|
44
|
-
it_behaves_like "都道府県が見つからない", code: 99
|
45
|
-
it_behaves_like "都道府県が見つかる", code: "1"
|
46
|
-
it_behaves_like "都道府県が見つかる", code: "01"
|
47
|
-
it_behaves_like "都道府県が見つからない", code: "99"
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '都道府県名' do
|
51
|
-
it_behaves_like "都道府県が見つかる", name: "北海道"
|
52
|
-
it_behaves_like "都道府県が見つからない", name: "うどん県"
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '都道府県名(英語表記)' do
|
56
|
-
it_behaves_like "都道府県が見つかる", name: "Hokkaido"
|
57
|
-
it_behaves_like "都道府県が見つからない", name: "Udon"
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '都道府県名(英語表記-小文字)' do
|
61
|
-
it_behaves_like "都道府県が見つかる", name: "hokkaido"
|
62
|
-
it_behaves_like "都道府県が見つからない", name: "udon"
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '都道府県名(ひらがな表記)' do
|
66
|
-
it_behaves_like "都道府県が見つかる", name: "ほっかいどう"
|
67
|
-
it_behaves_like "都道府県が見つからない", name: "うどん"
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '都道府県名(カタカナ表記)' do
|
71
|
-
it_behaves_like "都道府県が見つかる", name: "ホッカイドウ"
|
72
|
-
it_behaves_like "都道府県が見つからない", name: "ウドン"
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '都道府県名(前方一致)' do
|
76
|
-
let(:pref) { JpPrefecture::Prefecture.find(name: '東京') }
|
77
|
-
it { expect(pref.name).to eq '東京都' }
|
78
|
-
|
79
|
-
let(:pref2) { JpPrefecture::Prefecture.find(name: '京都') }
|
80
|
-
it { expect(pref2.name).to eq '京都府' }
|
81
|
-
|
82
|
-
context 'マッチする都道府県が複数あった場合' do
|
83
|
-
let(:pref) { JpPrefecture::Prefecture.find(name: '宮') }
|
84
|
-
it { expect(pref.name).to eq '宮城県' }
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'マッチする都道府県が複数あった場合(英語表記)' do
|
88
|
-
let(:pref) { JpPrefecture::Prefecture.find(name: 'miya') }
|
89
|
-
it { expect(pref.name_e).to eq 'Miyagi' }
|
90
|
-
|
91
|
-
let(:pref2) { JpPrefecture::Prefecture.find(name: 'Miya') }
|
92
|
-
it { expect(pref2.name_e).to eq 'Miyagi' }
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'マッチする都道府県が複数あった場合(ひらがな表記)' do
|
96
|
-
let(:pref) { JpPrefecture::Prefecture.find(name: 'みや') }
|
97
|
-
it { expect(pref.name_h).to eq 'みやぎけん' }
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'マッチする都道府県が複数あった場合(カタカナ表記)' do
|
101
|
-
let(:pref) { JpPrefecture::Prefecture.find(name: 'ミヤ') }
|
102
|
-
it { expect(pref.name_k).to eq 'ミヤギケン' }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '渡した変数について' do
|
108
|
-
context 'string の場合' do
|
109
|
-
it '値が変更されないこと' do
|
110
|
-
code = '1'
|
111
|
-
JpPrefecture::Prefecture.find(code)
|
112
|
-
expect(code).to eq '1'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'code が string の場合' do
|
117
|
-
it '値が変更されないこと' do
|
118
|
-
code = '1'
|
119
|
-
JpPrefecture::Prefecture.find(code: code)
|
120
|
-
expect(code).to eq '1'
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'name の場合' do
|
125
|
-
it '値が変更されないこと' do
|
126
|
-
name = 'hokkaido'
|
127
|
-
JpPrefecture::Prefecture.find(name: name)
|
128
|
-
expect(name).to eq 'hokkaido'
|
129
|
-
end
|
130
|
-
|
131
|
-
context '空の文字列が与えられた場合' do
|
132
|
-
it 'nilを返すこと' do
|
133
|
-
actual = JpPrefecture::Prefecture.find(name: '')
|
134
|
-
expect(actual).to be_nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'nilが与えられた場合' do
|
139
|
-
it 'nilを返すこと' do
|
140
|
-
actual = JpPrefecture::Prefecture.find(name: nil)
|
141
|
-
expect(actual).to be_nil
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'zip の場合' do
|
147
|
-
it '値が変更されないこと' do
|
148
|
-
zip = '9999999'
|
149
|
-
JpPrefecture::Prefecture.find(zip: zip)
|
150
|
-
expect(zip).to eq '9999999'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '.all' do
|
157
|
-
let(:prefs) { JpPrefecture::Prefecture.all }
|
158
|
-
it { expect(prefs.first).to be_an_instance_of(JpPrefecture::Prefecture) }
|
159
|
-
it '都道府県の数が 47 であること' do
|
160
|
-
expect(prefs.count).to eq 47
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
if ENV['CI']
|
3
|
-
require 'coveralls'
|
4
|
-
Coveralls.wear!
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'jp_prefecture'
|
8
|
-
require "active_record"
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.before(:suite) do
|
12
|
-
setup_db
|
13
|
-
end
|
14
|
-
|
15
|
-
config.after(:suite) do
|
16
|
-
teardown_db
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup_db
|
21
|
-
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
22
|
-
|
23
|
-
ActiveRecord::Schema.define(version: 1) do
|
24
|
-
create_table :places do |t|
|
25
|
-
t.integer :prefecture_code
|
26
|
-
t.integer :prefecture_id
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def teardown_db
|
32
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
33
|
-
ActiveRecord::Base.connection.drop_table(table)
|
34
|
-
end
|
35
|
-
end
|