clwy_china_city 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/app/assets/javascripts/clwy_china_city/application.js +3 -0
- data/app/assets/javascripts/{china_city/jquery.china_city.js → clwy_china_city/jquery.clwy_china_city.js} +3 -3
- data/app/assets/stylesheets/{china_city → clwy_china_city}/application.css +0 -0
- data/app/controllers/{china_city → clwy_china_city}/application_controller.rb +1 -1
- data/app/controllers/{china_city → clwy_china_city}/data_controller.rb +3 -3
- data/app/helpers/{china_city → clwy_china_city}/application_helper.rb +1 -1
- data/app/views/{china_city → clwy_china_city}/data/index.html.erb +5 -5
- data/app/views/layouts/clwy_china_city/application.html.erb +12 -0
- data/config/routes.rb +1 -1
- data/lib/{china_city.rb → clwy_china_city.rb} +2 -2
- data/lib/{china_city → clwy_china_city}/engine.rb +2 -2
- data/lib/clwy_china_city/version.rb +3 -0
- data/lib/{china_city_tasks.rake → clwy_china_city_tasks.rake} +0 -0
- data/spec/controllers/{china_city → clwy_china_city}/data_controller_spec.rb +2 -2
- data/spec/dummy/app/assets/javascripts/application.js +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/features/china_city_spec.rb +2 -2
- data/spec/lib/clwy_china_city_spec.rb +64 -0
- metadata +18 -18
- data/app/assets/javascripts/china_city/application.js +0 -3
- data/app/views/layouts/china_city/application.html.erb +0 -12
- data/lib/china_city/version.rb +0 -3
- data/spec/lib/china_city_spec.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39734bd5ea18bc83cf4b2ca3e445934846714d389a2958dfacf42f6a60cf62e5
|
4
|
+
data.tar.gz: 4d34b085ef06ad4fdc63417aca321afa3e56f11b202b96986af0d2f6bd9532e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a26bb9de5350ca3641208ebb6676597e48a60d42278fad1a15f41e04f37790430f531ea2f9bb735ebc6f0cf28b4f9b87c08a95b5f9759c69c076f4777a19ab4
|
7
|
+
data.tar.gz: 84e0c1f0bfae39338e7060ad22af49a3698d124bc7a63c93a79651a6f474260c49c5cfc5a3f247306a7cf79187236904b37331fa0e6257cd6b57e9672413aa1e
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ require 'appraisal'
|
|
9
9
|
|
10
10
|
RDoc::Task.new(:rdoc) do |rdoc|
|
11
11
|
rdoc.rdoc_dir = 'rdoc'
|
12
|
-
rdoc.title = '
|
12
|
+
rdoc.title = 'ClwyChinaCity'
|
13
13
|
rdoc.options << '--line-numbers'
|
14
14
|
rdoc.rdoc_files.include('README.rdoc')
|
15
15
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
@@ -28,4 +28,4 @@ desc "Run all specs in spec directory (excluding plugin specs)"
|
|
28
28
|
RSpec::Core::RakeTask.new(:spec)
|
29
29
|
task :default => :spec
|
30
30
|
|
31
|
-
load 'lib/
|
31
|
+
load 'lib/clwy_china_city_tasks.rake'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
(function() {
|
2
|
-
$.fn.
|
2
|
+
$.fn.clwy_china_city = function() {
|
3
3
|
return this.each(function() {
|
4
4
|
var selects;
|
5
5
|
selects = $(this).find('.city-select');
|
@@ -9,7 +9,7 @@
|
|
9
9
|
next_selects = selects.slice(selects.index(this) + 1);
|
10
10
|
$("option:gt(0)", next_selects).remove();
|
11
11
|
if (next_selects.first()[0] && $this.val()) {
|
12
|
-
return $.get("/
|
12
|
+
return $.get("/clwy_china_city/" + ($(this).val()), function(data) {
|
13
13
|
var i, len, option, results;
|
14
14
|
results = [];
|
15
15
|
for (i = 0, len = data.length; i < len; i++) {
|
@@ -24,7 +24,7 @@
|
|
24
24
|
};
|
25
25
|
|
26
26
|
$(document).on("turbolinks:load", function() {
|
27
|
-
return $('.city-group').
|
27
|
+
return $('.city-group').clwy_china_city();
|
28
28
|
});
|
29
29
|
|
30
30
|
}).call(this);
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_dependency "
|
1
|
+
require_dependency "clwy_china_city/application_controller"
|
2
2
|
|
3
|
-
module
|
3
|
+
module ClwyChinaCity
|
4
4
|
class DataController < ApplicationController
|
5
5
|
def show
|
6
|
-
data =
|
6
|
+
data = ClwyChinaCity.list(params[:id])
|
7
7
|
render json: data, layout: nil
|
8
8
|
end
|
9
9
|
|
@@ -3,10 +3,10 @@
|
|
3
3
|
city = '440300'
|
4
4
|
district = '440305'
|
5
5
|
street = '440305001'
|
6
|
-
provinces =
|
7
|
-
cities =
|
8
|
-
districtes =
|
9
|
-
streets =
|
6
|
+
provinces = ClwyChinaCity.list
|
7
|
+
cities = ClwyChinaCity.list(province)
|
8
|
+
districtes = ClwyChinaCity.list(city)
|
9
|
+
streets = ClwyChinaCity.list(district)
|
10
10
|
%>
|
11
11
|
<h2>Rails Helper</h2>
|
12
12
|
<div class='rails-helper city-group'>
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<div class='html-tag city-group'>
|
21
21
|
<select class='city-select city-province'>
|
22
22
|
<option>--省份--</option>
|
23
|
-
<%= options_for_select(
|
23
|
+
<%= options_for_select(ClwyChinaCity.list, province) %>
|
24
24
|
</select>
|
25
25
|
<select class='city-select city-city'>
|
26
26
|
<option>--城市--</option>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>ClwyChinaCity</title>
|
5
|
+
<%= stylesheet_link_tag "clwy_china_city/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "clwy_china_city/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
</body>
|
12
|
+
</html>
|
data/config/routes.rb
CHANGED
File without changes
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe ClwyChinaCity::DataController do
|
4
4
|
|
5
5
|
describe "GET 'show'" do
|
6
6
|
it "returns http success" do
|
7
|
-
get 'show', id: '000000', use_route: '
|
7
|
+
get 'show', id: '000000', use_route: 'clwy_china_city'
|
8
8
|
response.should be_success
|
9
9
|
end
|
10
10
|
end
|
@@ -10,5 +10,5 @@
|
|
10
10
|
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
12
12
|
//= require 'jquery'
|
13
|
-
//= require '
|
13
|
+
//= require 'clwy_china_city/jquery.clwy_china_city'
|
14
14
|
//= require_tree .
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
feature 'china city', js: true do
|
5
5
|
scenario 'select' do
|
6
|
-
visit '/
|
6
|
+
visit '/clwy_china_city'
|
7
7
|
within '.rails-helper' do
|
8
8
|
select '广东省'
|
9
9
|
select '深圳市'
|
@@ -18,7 +18,7 @@ feature 'china city', js: true do
|
|
18
18
|
|
19
19
|
describe 'clean' do
|
20
20
|
before do
|
21
|
-
visit '/
|
21
|
+
visit '/clwy_china_city'
|
22
22
|
within '.rails-helper' do
|
23
23
|
select '广东省'
|
24
24
|
select '深圳市'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ClwyChinaCity do
|
5
|
+
it 'should be list' do
|
6
|
+
# 省
|
7
|
+
ClwyChinaCity.list.should eql [["北京市", "110000"], ["天津市", "120000"], ["河北省", "130000"], ["山西省", "140000"], ["内蒙古自治区", "150000"], ["辽宁省", "210000"], ["吉林省", "220000"], ["黑龙江省", "230000"], ["上海市", "310000"], ["江苏省", "320000"], ["浙江省", "330000"], ["安徽省", "340000"], ["福建省", "350000"], ["江西省", "360000"], ["山东省", "370000"], ["河南省", "410000"], ["湖北省", "420000"], ["湖南省", "430000"], ["广东省", "440000"], ["广西壮族自治区", "450000"], ["海南省", "460000"], ["重庆市", "500000"], ["四川省", "510000"], ["贵州省", "520000"], ["云南省", "530000"], ["西藏自治区", "540000"], ["陕西省", "610000"], ["甘肃省", "620000"], ["青海省", "630000"], ["宁夏回族自治区", "640000"], ["新疆维吾尔自治区", "650000"]]
|
8
|
+
|
9
|
+
ClwyChinaCity.list(nil, show_all: true).should eql [["北京市", "110000"], ["天津市", "120000"], ["河北省", "130000"], ["山西省", "140000"], ["内蒙古自治区", "150000"], ["辽宁省", "210000"], ["吉林省", "220000"], ["黑龙江省", "230000"], ["上海市", "310000"], ["江苏省", "320000"], ["浙江省", "330000"], ["安徽省", "340000"], ["福建省", "350000"], ["江西省", "360000"], ["山东省", "370000"], ["河南省", "410000"], ["湖北省", "420000"], ["湖南省", "430000"], ["广东省", "440000"], ["广西壮族自治区", "450000"], ["海南省", "460000"], ["重庆市", "500000"], ["四川省", "510000"], ["贵州省", "520000"], ["云南省", "530000"], ["西藏自治区", "540000"], ["陕西省", "610000"], ["甘肃省", "620000"], ["青海省", "630000"], ["宁夏回族自治区", "640000"], ["新疆维吾尔自治区", "650000"], ["台湾省", "710000"], ["香港特别行政区", "810000"], ["澳门特别行政区", "820000"]]
|
10
|
+
|
11
|
+
#市
|
12
|
+
ClwyChinaCity.list('440000').should eql [["广州市", "440100"], ["韶关市", "440200"], ["深圳市", "440300"], ["珠海市", "440400"], ["汕头市", "440500"], ["佛山市", "440600"], ["江门市", "440700"], ["湛江市", "440800"], ["茂名市", "440900"], ["肇庆市", "441200"], ["惠州市", "441300"], ["梅州市", "441400"], ["汕尾市", "441500"], ["河源市", "441600"], ["阳江市", "441700"], ["清远市", "441800"], ["东莞市", "441900"], ["中山市", "442000"], ["潮州市", "445100"], ["揭阳市", "445200"], ["云浮市", "445300"]]
|
13
|
+
|
14
|
+
#区
|
15
|
+
ClwyChinaCity.list('440300').should eql [["市辖区", "440301"], ["罗湖区", "440303"], ["福田区", "440304"], ["南山区", "440305"], ["宝安区", "440306"], ["龙岗区", "440307"], ["盐田区", "440308"]]
|
16
|
+
|
17
|
+
#街道
|
18
|
+
ClwyChinaCity.list('440305').should eql [["南头街道", "440305001"], ["南山街道", "440305002"], ["沙河街道", "440305003"], ["蛇口街道", "440305005"], ["招商街道", "440305006"], ["粤海街道", "440305007"], ["桃源街道", "440305008"], ["西丽街道", "440305009"]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should be get' do
|
22
|
+
ClwyChinaCity.get('440000').should eql '广东省'
|
23
|
+
ClwyChinaCity.get('440300').should eql '深圳市'
|
24
|
+
ClwyChinaCity.get('440305').should eql '南山区'
|
25
|
+
ClwyChinaCity.get('440000' , prepend_parent: true).should eql '广东省'
|
26
|
+
ClwyChinaCity.get('440300' , prepend_parent: true).should eql '广东省深圳市'
|
27
|
+
ClwyChinaCity.get('440305' , prepend_parent: true).should eql '广东省深圳市南山区'
|
28
|
+
ClwyChinaCity.get('440305001', prepend_parent: true).should eql '广东省深圳市南山区南头街道'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be parse' do # 可以直接获取省、市
|
32
|
+
ClwyChinaCity.province('440000').should eql '440000' # 省
|
33
|
+
ClwyChinaCity.city('440000').should eql '440000'
|
34
|
+
ClwyChinaCity.district('440000').should eql '440000'
|
35
|
+
ClwyChinaCity.province('440300').should eql '440000' # 市
|
36
|
+
ClwyChinaCity.city('440300').should eql '440300'
|
37
|
+
ClwyChinaCity.district('440300').should eql '440300'
|
38
|
+
ClwyChinaCity.province('440305').should eql '440000' # 区
|
39
|
+
ClwyChinaCity.city('440305').should eql '440300'
|
40
|
+
ClwyChinaCity.district('440305').should eql '440305'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should has children' do # 省市区都有子记录
|
44
|
+
data = ClwyChinaCity.data
|
45
|
+
|
46
|
+
# 省
|
47
|
+
empty_provinces = data.select{|k, v| v[:children].empty?}
|
48
|
+
# empty_provinces.should be_empty
|
49
|
+
# 港澳台暂时没有子记录
|
50
|
+
empty_provinces.keys.should eql ["710000", "810000", "820000"]
|
51
|
+
|
52
|
+
# 市
|
53
|
+
cities = {}
|
54
|
+
data.each {|k, v| v[:children].each{|ck, cv| cities[ck] = cv}}
|
55
|
+
empty_cities = cities.select{|k, v| v[:children].empty?}
|
56
|
+
empty_cities.should be_empty
|
57
|
+
|
58
|
+
# 区
|
59
|
+
districts = {}
|
60
|
+
cities.each {|k, v| v[:children].each{|ck, cv| districts[ck] = cv}}
|
61
|
+
empty_districts = districts.select{|k, v| v[:children].nil?}
|
62
|
+
empty_districts.should be_empty
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clwy_china_city
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dong Liu
|
@@ -179,22 +179,22 @@ extra_rdoc_files: []
|
|
179
179
|
files:
|
180
180
|
- MIT-LICENSE
|
181
181
|
- Rakefile
|
182
|
-
- app/assets/javascripts/
|
183
|
-
- app/assets/javascripts/
|
184
|
-
- app/assets/stylesheets/
|
185
|
-
- app/controllers/
|
186
|
-
- app/controllers/
|
187
|
-
- app/helpers/
|
188
|
-
- app/views/
|
189
|
-
- app/views/layouts/
|
182
|
+
- app/assets/javascripts/clwy_china_city/application.js
|
183
|
+
- app/assets/javascripts/clwy_china_city/jquery.clwy_china_city.js
|
184
|
+
- app/assets/stylesheets/clwy_china_city/application.css
|
185
|
+
- app/controllers/clwy_china_city/application_controller.rb
|
186
|
+
- app/controllers/clwy_china_city/data_controller.rb
|
187
|
+
- app/helpers/clwy_china_city/application_helper.rb
|
188
|
+
- app/views/clwy_china_city/data/index.html.erb
|
189
|
+
- app/views/layouts/clwy_china_city/application.html.erb
|
190
190
|
- config/routes.rb
|
191
191
|
- db/areas.json
|
192
192
|
- db/district_gb2260_taobao.yml
|
193
|
-
- lib/
|
194
|
-
- lib/
|
195
|
-
- lib/
|
196
|
-
- lib/
|
197
|
-
- spec/controllers/
|
193
|
+
- lib/clwy_china_city.rb
|
194
|
+
- lib/clwy_china_city/engine.rb
|
195
|
+
- lib/clwy_china_city/version.rb
|
196
|
+
- lib/clwy_china_city_tasks.rake
|
197
|
+
- spec/controllers/clwy_china_city/data_controller_spec.rb
|
198
198
|
- spec/dummy/README.rdoc
|
199
199
|
- spec/dummy/Rakefile
|
200
200
|
- spec/dummy/app/assets/javascripts/application.js
|
@@ -228,9 +228,9 @@ files:
|
|
228
228
|
- spec/dummy/public/favicon.ico
|
229
229
|
- spec/dummy/script/rails
|
230
230
|
- spec/features/china_city_spec.rb
|
231
|
-
- spec/lib/
|
231
|
+
- spec/lib/clwy_china_city_spec.rb
|
232
232
|
- spec/spec_helper.rb
|
233
|
-
homepage: https://github.com/clwy-cn/
|
233
|
+
homepage: https://github.com/clwy-cn/clwy_china_city
|
234
234
|
licenses:
|
235
235
|
- MIT
|
236
236
|
metadata: {}
|
@@ -288,5 +288,5 @@ test_files:
|
|
288
288
|
- spec/dummy/public/404.html
|
289
289
|
- spec/dummy/README.rdoc
|
290
290
|
- spec/features/china_city_spec.rb
|
291
|
-
- spec/lib/
|
292
|
-
- spec/controllers/
|
291
|
+
- spec/lib/clwy_china_city_spec.rb
|
292
|
+
- spec/controllers/clwy_china_city/data_controller_spec.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>ChinaCity</title>
|
5
|
-
<%= stylesheet_link_tag "china_city/application", media: "all" %>
|
6
|
-
<%= javascript_include_tag "china_city/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
|
9
|
-
<body>
|
10
|
-
<%= yield %>
|
11
|
-
</body>
|
12
|
-
</html>
|
data/lib/china_city/version.rb
DELETED
data/spec/lib/china_city_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe ChinaCity do
|
5
|
-
it 'should be list' do
|
6
|
-
# 省
|
7
|
-
ChinaCity.list.should eql [["北京市", "110000"], ["天津市", "120000"], ["河北省", "130000"], ["山西省", "140000"], ["内蒙古自治区", "150000"], ["辽宁省", "210000"], ["吉林省", "220000"], ["黑龙江省", "230000"], ["上海市", "310000"], ["江苏省", "320000"], ["浙江省", "330000"], ["安徽省", "340000"], ["福建省", "350000"], ["江西省", "360000"], ["山东省", "370000"], ["河南省", "410000"], ["湖北省", "420000"], ["湖南省", "430000"], ["广东省", "440000"], ["广西壮族自治区", "450000"], ["海南省", "460000"], ["重庆市", "500000"], ["四川省", "510000"], ["贵州省", "520000"], ["云南省", "530000"], ["西藏自治区", "540000"], ["陕西省", "610000"], ["甘肃省", "620000"], ["青海省", "630000"], ["宁夏回族自治区", "640000"], ["新疆维吾尔自治区", "650000"]]
|
8
|
-
|
9
|
-
ChinaCity.list(nil, show_all: true).should eql [["北京市", "110000"], ["天津市", "120000"], ["河北省", "130000"], ["山西省", "140000"], ["内蒙古自治区", "150000"], ["辽宁省", "210000"], ["吉林省", "220000"], ["黑龙江省", "230000"], ["上海市", "310000"], ["江苏省", "320000"], ["浙江省", "330000"], ["安徽省", "340000"], ["福建省", "350000"], ["江西省", "360000"], ["山东省", "370000"], ["河南省", "410000"], ["湖北省", "420000"], ["湖南省", "430000"], ["广东省", "440000"], ["广西壮族自治区", "450000"], ["海南省", "460000"], ["重庆市", "500000"], ["四川省", "510000"], ["贵州省", "520000"], ["云南省", "530000"], ["西藏自治区", "540000"], ["陕西省", "610000"], ["甘肃省", "620000"], ["青海省", "630000"], ["宁夏回族自治区", "640000"], ["新疆维吾尔自治区", "650000"], ["台湾省", "710000"], ["香港特别行政区", "810000"], ["澳门特别行政区", "820000"]]
|
10
|
-
|
11
|
-
#市
|
12
|
-
ChinaCity.list('440000').should eql [["广州市", "440100"], ["韶关市", "440200"], ["深圳市", "440300"], ["珠海市", "440400"], ["汕头市", "440500"], ["佛山市", "440600"], ["江门市", "440700"], ["湛江市", "440800"], ["茂名市", "440900"], ["肇庆市", "441200"], ["惠州市", "441300"], ["梅州市", "441400"], ["汕尾市", "441500"], ["河源市", "441600"], ["阳江市", "441700"], ["清远市", "441800"], ["东莞市", "441900"], ["中山市", "442000"], ["潮州市", "445100"], ["揭阳市", "445200"], ["云浮市", "445300"]]
|
13
|
-
|
14
|
-
#区
|
15
|
-
ChinaCity.list('440300').should eql [["市辖区", "440301"], ["罗湖区", "440303"], ["福田区", "440304"], ["南山区", "440305"], ["宝安区", "440306"], ["龙岗区", "440307"], ["盐田区", "440308"]]
|
16
|
-
|
17
|
-
#街道
|
18
|
-
ChinaCity.list('440305').should eql [["南头街道", "440305001"], ["南山街道", "440305002"], ["沙河街道", "440305003"], ["蛇口街道", "440305005"], ["招商街道", "440305006"], ["粤海街道", "440305007"], ["桃源街道", "440305008"], ["西丽街道", "440305009"]]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should be get' do
|
22
|
-
ChinaCity.get('440000').should eql '广东省'
|
23
|
-
ChinaCity.get('440300').should eql '深圳市'
|
24
|
-
ChinaCity.get('440305').should eql '南山区'
|
25
|
-
ChinaCity.get('440000' , prepend_parent: true).should eql '广东省'
|
26
|
-
ChinaCity.get('440300' , prepend_parent: true).should eql '广东省深圳市'
|
27
|
-
ChinaCity.get('440305' , prepend_parent: true).should eql '广东省深圳市南山区'
|
28
|
-
ChinaCity.get('440305001', prepend_parent: true).should eql '广东省深圳市南山区南头街道'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should be parse' do # 可以直接获取省、市
|
32
|
-
ChinaCity.province('440000').should eql '440000' # 省
|
33
|
-
ChinaCity.city('440000').should eql '440000'
|
34
|
-
ChinaCity.district('440000').should eql '440000'
|
35
|
-
ChinaCity.province('440300').should eql '440000' # 市
|
36
|
-
ChinaCity.city('440300').should eql '440300'
|
37
|
-
ChinaCity.district('440300').should eql '440300'
|
38
|
-
ChinaCity.province('440305').should eql '440000' # 区
|
39
|
-
ChinaCity.city('440305').should eql '440300'
|
40
|
-
ChinaCity.district('440305').should eql '440305'
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should has children' do # 省市区都有子记录
|
44
|
-
data = ChinaCity.data
|
45
|
-
|
46
|
-
# 省
|
47
|
-
empty_provinces = data.select{|k, v| v[:children].empty?}
|
48
|
-
# empty_provinces.should be_empty
|
49
|
-
# 港澳台暂时没有子记录
|
50
|
-
empty_provinces.keys.should eql ["710000", "810000", "820000"]
|
51
|
-
|
52
|
-
# 市
|
53
|
-
cities = {}
|
54
|
-
data.each {|k, v| v[:children].each{|ck, cv| cities[ck] = cv}}
|
55
|
-
empty_cities = cities.select{|k, v| v[:children].empty?}
|
56
|
-
empty_cities.should be_empty
|
57
|
-
|
58
|
-
# 区
|
59
|
-
districts = {}
|
60
|
-
cities.each {|k, v| v[:children].each{|ck, cv| districts[ck] = cv}}
|
61
|
-
empty_districts = districts.select{|k, v| v[:children].nil?}
|
62
|
-
empty_districts.should be_empty
|
63
|
-
end
|
64
|
-
end
|