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.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/app/assets/javascripts/clwy_china_city/application.js +3 -0
  4. data/app/assets/javascripts/{china_city/jquery.china_city.js → clwy_china_city/jquery.clwy_china_city.js} +3 -3
  5. data/app/assets/stylesheets/{china_city → clwy_china_city}/application.css +0 -0
  6. data/app/controllers/{china_city → clwy_china_city}/application_controller.rb +1 -1
  7. data/app/controllers/{china_city → clwy_china_city}/data_controller.rb +3 -3
  8. data/app/helpers/{china_city → clwy_china_city}/application_helper.rb +1 -1
  9. data/app/views/{china_city → clwy_china_city}/data/index.html.erb +5 -5
  10. data/app/views/layouts/clwy_china_city/application.html.erb +12 -0
  11. data/config/routes.rb +1 -1
  12. data/lib/{china_city.rb → clwy_china_city.rb} +2 -2
  13. data/lib/{china_city → clwy_china_city}/engine.rb +2 -2
  14. data/lib/clwy_china_city/version.rb +3 -0
  15. data/lib/{china_city_tasks.rake → clwy_china_city_tasks.rake} +0 -0
  16. data/spec/controllers/{china_city → clwy_china_city}/data_controller_spec.rb +2 -2
  17. data/spec/dummy/app/assets/javascripts/application.js +1 -1
  18. data/spec/dummy/config/application.rb +1 -1
  19. data/spec/dummy/config/routes.rb +1 -1
  20. data/spec/features/china_city_spec.rb +2 -2
  21. data/spec/lib/clwy_china_city_spec.rb +64 -0
  22. metadata +18 -18
  23. data/app/assets/javascripts/china_city/application.js +0 -3
  24. data/app/views/layouts/china_city/application.html.erb +0 -12
  25. data/lib/china_city/version.rb +0 -3
  26. data/spec/lib/china_city_spec.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d609d017cdb6ae6e183777f5b81cb6fbc14287dfc07a9850e676b67e163650a
4
- data.tar.gz: 9afe8e8966f17f47f67e5c31a41141c5fdf716d73ef6d5ee1648f06d736e59d6
3
+ metadata.gz: 39734bd5ea18bc83cf4b2ca3e445934846714d389a2958dfacf42f6a60cf62e5
4
+ data.tar.gz: 4d34b085ef06ad4fdc63417aca321afa3e56f11b202b96986af0d2f6bd9532e0
5
5
  SHA512:
6
- metadata.gz: d15e10ba5dc94622e34cc95bd8c473b5a682137bb3e0a067b1b82db9d9a1aa56cf203d34504e78a6360f762a10fc3375afd5522b1ec7f894353430eebb9a51c5
7
- data.tar.gz: b7f83a90edc1ff5959718217be4d95ff5258dda9ce6b90e105dd6e73d58663b61a68b10d76613b33cab5a92488c1ed1e973f82f5cbd92bc2e2a449010b2b5010
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 = 'ChinaCity'
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/china_city_tasks.rake'
31
+ load 'lib/clwy_china_city_tasks.rake'
@@ -0,0 +1,3 @@
1
+ //= require jquery
2
+ //= require clwy_china_city/jquery.clwy_china_city
3
+ //= require_tree .
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- $.fn.china_city = function() {
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("/china_city/" + ($(this).val()), function(data) {
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').china_city();
27
+ return $('.city-group').clwy_china_city();
28
28
  });
29
29
 
30
30
  }).call(this);
@@ -1,4 +1,4 @@
1
- module ChinaCity
1
+ module ClwyChinaCity
2
2
  class ApplicationController < ActionController::Base
3
3
  end
4
4
  end
@@ -1,9 +1,9 @@
1
- require_dependency "china_city/application_controller"
1
+ require_dependency "clwy_china_city/application_controller"
2
2
 
3
- module ChinaCity
3
+ module ClwyChinaCity
4
4
  class DataController < ApplicationController
5
5
  def show
6
- data = ChinaCity.list(params[:id])
6
+ data = ClwyChinaCity.list(params[:id])
7
7
  render json: data, layout: nil
8
8
  end
9
9
 
@@ -1,4 +1,4 @@
1
- module ChinaCity
1
+ module ClwyChinaCity
2
2
  module ApplicationHelper
3
3
  end
4
4
  end
@@ -3,10 +3,10 @@
3
3
  city = '440300'
4
4
  district = '440305'
5
5
  street = '440305001'
6
- provinces = ChinaCity.list
7
- cities = ChinaCity.list(province)
8
- districtes = ChinaCity.list(city)
9
- streets = ChinaCity.list(district)
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(ChinaCity.list, province) %>
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>
@@ -1,4 +1,4 @@
1
- ChinaCity::Engine.routes.draw do
1
+ ClwyChinaCity::Engine.routes.draw do
2
2
  root to: 'data#index'
3
3
  get ':id', to: 'data#show'
4
4
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
- require "china_city/engine"
2
+ require "clwy_china_city/engine"
3
3
 
4
- module ChinaCity
4
+ module ClwyChinaCity
5
5
  CHINA = '000000' # 全国
6
6
  PATTERN = /(\d{2})(\d{2})(\d{2})/
7
7
 
@@ -1,6 +1,6 @@
1
- module ChinaCity
1
+ module ClwyChinaCity
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace ChinaCity
3
+ isolate_namespace ClwyChinaCity
4
4
 
5
5
  config.generators do |g|
6
6
  g.test_framework :rspec, fixture: false
@@ -0,0 +1,3 @@
1
+ module ClwyChinaCity
2
+ VERSION = "0.0.7"
3
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ChinaCity::DataController do
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: 'china_city'
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 'china_city/jquery.china_city'
13
+ //= require 'clwy_china_city/jquery.clwy_china_city'
14
14
  //= require_tree .
@@ -8,7 +8,7 @@ require "sprockets/railtie"
8
8
  # require "rails/test_unit/railtie"
9
9
 
10
10
  Bundler.require(*Rails.groups)
11
- require "china_city"
11
+ require "clwy_china_city"
12
12
 
13
13
  module Dummy
14
14
  class Application < Rails::Application
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount ChinaCity::Engine => "/china_city"
3
+ mount ClwyChinaCity::Engine => "/clwy_china_city"
4
4
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  feature 'china city', js: true do
5
5
  scenario 'select' do
6
- visit '/china_city'
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 '/china_city'
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.6
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/china_city/application.js
183
- - app/assets/javascripts/china_city/jquery.china_city.js
184
- - app/assets/stylesheets/china_city/application.css
185
- - app/controllers/china_city/application_controller.rb
186
- - app/controllers/china_city/data_controller.rb
187
- - app/helpers/china_city/application_helper.rb
188
- - app/views/china_city/data/index.html.erb
189
- - app/views/layouts/china_city/application.html.erb
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/china_city.rb
194
- - lib/china_city/engine.rb
195
- - lib/china_city/version.rb
196
- - lib/china_city_tasks.rake
197
- - spec/controllers/china_city/data_controller_spec.rb
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/china_city_spec.rb
231
+ - spec/lib/clwy_china_city_spec.rb
232
232
  - spec/spec_helper.rb
233
- homepage: https://github.com/clwy-cn/china_city
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/china_city_spec.rb
292
- - spec/controllers/china_city/data_controller_spec.rb
291
+ - spec/lib/clwy_china_city_spec.rb
292
+ - spec/controllers/clwy_china_city/data_controller_spec.rb
@@ -1,3 +0,0 @@
1
- //= require jquery
2
- //= require china_city/jquery.china_city
3
- //= require_tree .
@@ -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>
@@ -1,3 +0,0 @@
1
- module ChinaCity
2
- VERSION = "0.0.6"
3
- end
@@ -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