clwy_china_city 0.0.6 → 0.0.9
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 → clwy_china_city}/engine.rb +2 -2
- data/lib/clwy_china_city/version.rb +3 -0
- data/lib/{china_city.rb → clwy_china_city.rb} +2 -2
- 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 +44 -50
- 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: 65ddf2576f1c812b2cf0fe4ec4094917a1bd54168e7e6ff855f9cea4bb9fd415
|
4
|
+
data.tar.gz: f572ce9c09e869f98da21910a4b330669eaa6bb14ef47dbd7ef1918e5b654271
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f85175e704c485374373906969e2e8670d7fa91355706f10a9b1295c2d4def155810086d6e0ff7e0b19ac6f97d46498e4d8043da4f0a96193ab811f1ba4f803
|
7
|
+
data.tar.gz: 50f679c7130febaa62700df5ac9423e47f883bd665c2fcfff179c23ea84e02a79dc9cc401fd6de0119ad1440192038666a71028d7aaa1e72b3e18cc7c401ec60
|
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,14 +1,14 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dong Liu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '7'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,21 +24,18 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '5'
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '7'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: jquery-rails
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '4'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
|
-
- - "
|
38
|
+
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '4'
|
47
41
|
- !ruby/object:Gem::Dependency
|
@@ -179,22 +173,22 @@ extra_rdoc_files: []
|
|
179
173
|
files:
|
180
174
|
- MIT-LICENSE
|
181
175
|
- 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/
|
176
|
+
- app/assets/javascripts/clwy_china_city/application.js
|
177
|
+
- app/assets/javascripts/clwy_china_city/jquery.clwy_china_city.js
|
178
|
+
- app/assets/stylesheets/clwy_china_city/application.css
|
179
|
+
- app/controllers/clwy_china_city/application_controller.rb
|
180
|
+
- app/controllers/clwy_china_city/data_controller.rb
|
181
|
+
- app/helpers/clwy_china_city/application_helper.rb
|
182
|
+
- app/views/clwy_china_city/data/index.html.erb
|
183
|
+
- app/views/layouts/clwy_china_city/application.html.erb
|
190
184
|
- config/routes.rb
|
191
185
|
- db/areas.json
|
192
186
|
- db/district_gb2260_taobao.yml
|
193
|
-
- lib/
|
194
|
-
- lib/
|
195
|
-
- lib/
|
196
|
-
- lib/
|
197
|
-
- spec/controllers/
|
187
|
+
- lib/clwy_china_city.rb
|
188
|
+
- lib/clwy_china_city/engine.rb
|
189
|
+
- lib/clwy_china_city/version.rb
|
190
|
+
- lib/clwy_china_city_tasks.rake
|
191
|
+
- spec/controllers/clwy_china_city/data_controller_spec.rb
|
198
192
|
- spec/dummy/README.rdoc
|
199
193
|
- spec/dummy/Rakefile
|
200
194
|
- spec/dummy/app/assets/javascripts/application.js
|
@@ -228,13 +222,13 @@ files:
|
|
228
222
|
- spec/dummy/public/favicon.ico
|
229
223
|
- spec/dummy/script/rails
|
230
224
|
- spec/features/china_city_spec.rb
|
231
|
-
- spec/lib/
|
225
|
+
- spec/lib/clwy_china_city_spec.rb
|
232
226
|
- spec/spec_helper.rb
|
233
|
-
homepage: https://github.com/clwy-cn/
|
227
|
+
homepage: https://github.com/clwy-cn/clwy_china_city
|
234
228
|
licenses:
|
235
229
|
- MIT
|
236
230
|
metadata: {}
|
237
|
-
post_install_message:
|
231
|
+
post_install_message:
|
238
232
|
rdoc_options: []
|
239
233
|
require_paths:
|
240
234
|
- lib
|
@@ -249,44 +243,44 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
243
|
- !ruby/object:Gem::Version
|
250
244
|
version: '0'
|
251
245
|
requirements: []
|
252
|
-
rubygems_version: 3.
|
253
|
-
signing_key:
|
246
|
+
rubygems_version: 3.3.7
|
247
|
+
signing_key:
|
254
248
|
specification_version: 4
|
255
249
|
summary: a gem to help you select chinese area
|
256
250
|
test_files:
|
257
|
-
- spec/
|
258
|
-
- spec/dummy/
|
259
|
-
- spec/dummy/
|
251
|
+
- spec/controllers/clwy_china_city/data_controller_spec.rb
|
252
|
+
- spec/dummy/README.rdoc
|
253
|
+
- spec/dummy/Rakefile
|
260
254
|
- spec/dummy/app/assets/javascripts/application.js
|
261
255
|
- spec/dummy/app/assets/stylesheets/application.css
|
256
|
+
- spec/dummy/app/controllers/application_controller.rb
|
262
257
|
- spec/dummy/app/helpers/application_helper.rb
|
263
|
-
- spec/dummy/
|
258
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
264
259
|
- spec/dummy/bin/bundle
|
265
260
|
- spec/dummy/bin/rails
|
266
|
-
- spec/dummy/
|
267
|
-
- spec/dummy/config/locales/en.yml
|
268
|
-
- spec/dummy/config/environments/production.rb
|
269
|
-
- spec/dummy/config/environments/development.rb
|
270
|
-
- spec/dummy/config/environments/test.rb
|
271
|
-
- spec/dummy/config/environment.rb
|
261
|
+
- spec/dummy/bin/rake
|
272
262
|
- spec/dummy/config/application.rb
|
273
|
-
- spec/dummy/config/database.yml
|
274
263
|
- spec/dummy/config/boot.rb
|
264
|
+
- spec/dummy/config/database.yml
|
265
|
+
- spec/dummy/config/environment.rb
|
266
|
+
- spec/dummy/config/environments/development.rb
|
267
|
+
- spec/dummy/config/environments/production.rb
|
268
|
+
- spec/dummy/config/environments/test.rb
|
275
269
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
276
|
-
- spec/dummy/config/initializers/mime_types.rb
|
277
270
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
271
|
+
- spec/dummy/config/initializers/inflections.rb
|
272
|
+
- spec/dummy/config/initializers/mime_types.rb
|
273
|
+
- spec/dummy/config/initializers/secret_token.rb
|
278
274
|
- spec/dummy/config/initializers/session_store.rb
|
279
275
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
280
|
-
- spec/dummy/config/
|
281
|
-
- spec/dummy/config/
|
276
|
+
- spec/dummy/config/locales/en.yml
|
277
|
+
- spec/dummy/config/routes.rb
|
282
278
|
- spec/dummy/config.ru
|
283
|
-
- spec/dummy/
|
284
|
-
- spec/dummy/Rakefile
|
285
|
-
- spec/dummy/public/favicon.ico
|
279
|
+
- spec/dummy/public/404.html
|
286
280
|
- spec/dummy/public/422.html
|
287
281
|
- spec/dummy/public/500.html
|
288
|
-
- spec/dummy/public/
|
289
|
-
- spec/dummy/
|
282
|
+
- spec/dummy/public/favicon.ico
|
283
|
+
- spec/dummy/script/rails
|
290
284
|
- spec/features/china_city_spec.rb
|
291
|
-
- spec/lib/
|
292
|
-
- spec/
|
285
|
+
- spec/lib/clwy_china_city_spec.rb
|
286
|
+
- spec/spec_helper.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
|