unidom-geo-china 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52810a4565400a8aef20f4bd31a99ca22e24d71c
|
4
|
+
data.tar.gz: 67f3ed45ab394f6ef0b0b5a5b1e448c8b3452f2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25ab5059fac40274cad8b47112d1f0ee9745da664880b5bd9a7d89e000e5df3ba37e673a6e2b0771d10a071bddae4b8d7a0d912ed63712ae9d31386c6125343f
|
7
|
+
data.tar.gz: 0245d3e995dfd93c8f6359d13e11f158e295bb1815f347a12415063f0ca3a6af97fb266f373cebe16200b1bb64895115895f92b779d008d3906c55eb4519ca06
|
data/README.md
CHANGED
@@ -6,28 +6,43 @@
|
|
6
6
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The China Geo domain model engine includes the Region model and its migration.
|
7
7
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。中国地理领域模型引擎包括中国大陆的行政区划模型及其数据迁移脚本。
|
8
8
|
|
9
|
+
|
10
|
+
|
9
11
|
## Recent Update
|
12
|
+
|
10
13
|
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
11
14
|
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
12
15
|
|
16
|
+
|
17
|
+
|
13
18
|
## Usage in Gemfile
|
19
|
+
|
14
20
|
```ruby
|
15
21
|
gem 'unidom-geo-china'
|
16
22
|
```
|
17
23
|
|
24
|
+
|
25
|
+
|
18
26
|
## Run the Database Migration
|
27
|
+
|
19
28
|
```shell
|
20
29
|
rake db:migrate
|
21
30
|
```
|
22
31
|
The migration versions start with 2001049156.
|
23
32
|
|
33
|
+
|
34
|
+
|
24
35
|
## Import Data
|
36
|
+
|
25
37
|
```shell
|
26
38
|
bundle exec rake unidom:geo:china:region:import file=/china-region-data/NBS-county/20141031.csv from_date=2014-10-31 scheme_id= scheme_type=
|
27
39
|
bundle exec rake unidom:geo:china:town:import file=/china-region-data/NBS-town/20141031.csv from_date=2014-10-31 scheme_id= scheme_type=
|
28
40
|
```
|
29
41
|
|
42
|
+
|
43
|
+
|
30
44
|
## Call the Model
|
45
|
+
|
31
46
|
```ruby
|
32
47
|
Unidom::Geo::China::Region.root_level # All the 31 province-level regions including Beijing, Tianjin, etc.
|
33
48
|
Unidom::Geo::China::Region.numeric_coded_as('120000').valid_at.alive.first # Tianjin (天津)
|
@@ -35,3 +50,30 @@ Unidom::Geo::China::Region.numeric_coded_as('120000').valid_at.alive.first # Tia
|
|
35
50
|
active_locations = region.locations.valid_at.alive
|
36
51
|
active_towns = region.towns.valid_at.alive
|
37
52
|
```
|
53
|
+
|
54
|
+
The Region model has a lot of domain knowlegde of the China regions.
|
55
|
+
- ```region.numeric_code_middle_empty?``` indicates whether the ```region``` is a province. 判断行政区划是否是一个省、直辖市、或者自治区。
|
56
|
+
- ```!region.numeric_code_middle_empty?&®ion.numeric_code_suffix_empty?``` indicates whether the ```region``` is a city. 判断行政区划是否是一个地级市、地区、自治州、盟。
|
57
|
+
- ```!region..numeric_code_suffix_empty?``` indicates whether the ```region``` is a county. 判断行政区划是否是一个自治县、县级市、旗、自治旗、市辖区、林区、特区。
|
58
|
+
- ```region.mducg?``` indicates whether the ```region``` is a municipality direct under central government. 判断行政区划是否是一个直辖市。
|
59
|
+
-
|
60
|
+
```region.under_mducg?``` indicates whether the ```region``` is under any municipality direct under central government. 判断行政区划是否是一个直辖市的下级行政区划。
|
61
|
+
- ```region.under? another_region``` indicates the ```region``` is under the given another_region. 判断行政区划是否是一个给定行政区划的下级(含直接和间接下级)。
|
62
|
+
- ```region.super_regions``` returns a scope for the super regions of the ```region```. 返回找到 ```region``` 直接上级行政区划的查询 scope。
|
63
|
+
- ```region.sub_regions``` returns a scope for the sub regions of the ```region```. 返回找到 ```region``` 直接下级行政区划的查询 scope。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
## Include the Concerns
|
68
|
+
```ruby
|
69
|
+
include Unidom::Geo::China::Concerns::AsInferiorRegion
|
70
|
+
include Unidom::Geo::China::Concerns::AsSuperiorRegion
|
71
|
+
```
|
72
|
+
|
73
|
+
### As Inferior Region
|
74
|
+
The As Inferior Region do the following tasks for the includer automatically:
|
75
|
+
1. Define the #super_regions method as: ``super_regions``
|
76
|
+
|
77
|
+
### As Superior Region
|
78
|
+
The As Superior Region do the following tasks for the includer automatically:
|
79
|
+
1. Define the #sub_regions method as: ``sub_regions``
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Unidom::Geo::China::Concerns::AsInferiorRegion
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do |includer|
|
6
|
+
|
7
|
+
def super_regions
|
8
|
+
numeric_code_suffix_empty? ? (numeric_code_middle_empty? ? self.class.none : self.class.numeric_coded_as("#{numeric_code_prefix}0000")) : self.class.numeric_coded_as("#{numeric_code_prefix}#{numeric_code_middle}00")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Unidom::Geo::China::Concerns::AsSuperiorRegion
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do |includer|
|
6
|
+
|
7
|
+
def sub_regions
|
8
|
+
if numeric_code_suffix_empty?
|
9
|
+
prefix = numeric_code_middle_empty? ? numeric_code_prefix : "#{numeric_code_prefix}#{numeric_code_middle}"
|
10
|
+
regions = self.class.numeric_code_starting_with(prefix).not_numeric_coded_as(numeric_code)
|
11
|
+
regions = regions.numeric_code_ending_with('00') if numeric_code_middle_empty?
|
12
|
+
regions
|
13
|
+
else
|
14
|
+
self.class.none
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -27,6 +27,8 @@ class Unidom::Geo::China::Region < ActiveRecord::Base
|
|
27
27
|
|
28
28
|
include Unidom::Common::Concerns::ModelExtension
|
29
29
|
include Unidom::Geo::Concerns::AsRegion
|
30
|
+
include Unidom::Geo::China::Concerns::AsInferiorRegion
|
31
|
+
include Unidom::Geo::China::Concerns::AsSuperiorRegion
|
30
32
|
|
31
33
|
validates :numeric_code, numericality: { integer_only: true }
|
32
34
|
validates :alphabetic_code, allow_blank: true, length: { minimum: 2 }
|
@@ -34,9 +36,6 @@ class Unidom::Geo::China::Region < ActiveRecord::Base
|
|
34
36
|
|
35
37
|
belongs_to :scheme, polymorphic: true
|
36
38
|
|
37
|
-
#has_many :locations, class_name: 'Unidom::Geo::Location', as: :region
|
38
|
-
#has_many :locatings, through: :locations, source: :locatings
|
39
|
-
|
40
39
|
has_many :towns, class_name: 'Unidom::Geo::China::Town'
|
41
40
|
|
42
41
|
scope :scheme_is, ->(scheme) { scheme.present? ? where(scheme: scheme) : scheme_id_is.scheme_type_is }
|
@@ -80,6 +79,7 @@ class Unidom::Geo::China::Region < ActiveRecord::Base
|
|
80
79
|
under_mducg? && numeric_code_middle_empty? && numeric_code_suffix_empty?
|
81
80
|
end
|
82
81
|
|
82
|
+
=begin
|
83
83
|
def super_regions
|
84
84
|
numeric_code_suffix_empty? ? (numeric_code_middle_empty? ? self.class.none : self.class.numeric_coded_as("#{numeric_code_prefix}0000")) : self.class.numeric_coded_as("#{numeric_code_prefix}#{numeric_code_middle}00")
|
85
85
|
end
|
@@ -94,6 +94,7 @@ class Unidom::Geo::China::Region < ActiveRecord::Base
|
|
94
94
|
self.class.none
|
95
95
|
end
|
96
96
|
end
|
97
|
+
=end
|
97
98
|
|
98
99
|
def full_name(separator = ' ')
|
99
100
|
final_name = self.name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-geo-china
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -40,6 +40,8 @@ files:
|
|
40
40
|
- app/assets/stylesheets/unidom/geo/china/application.css
|
41
41
|
- app/controllers/unidom/geo/china/application_controller.rb
|
42
42
|
- app/helpers/unidom/geo/china/application_helper.rb
|
43
|
+
- app/models/unidom/geo/china/concerns/as_inferior_region.rb
|
44
|
+
- app/models/unidom/geo/china/concerns/as_superior_region.rb
|
43
45
|
- app/models/unidom/geo/china/region.rb
|
44
46
|
- app/models/unidom/geo/china/town.rb
|
45
47
|
- app/views/layouts/unidom/geo/china/application.html.erb
|