unidom-geo-china 0.5.7 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/models/unidom/geo/china/region.rb +19 -0
- data/app/models/unidom/geo/china/town.rb +1 -1
- data/db/migrate/20010491560010_create_unidom_china_regions.rb +4 -4
- data/db/migrate/20010491560020_create_unidom_china_towns.rb +4 -4
- data/lib/rspec/models/unidom/geo/china/region_spec.rb +64 -0
- data/lib/unidom/geo/china/version.rb +1 -1
- metadata +8 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 311edb0fbbb12609b7eedc18a3491248de71f500547db17fb754203eac9823ac
|
4
|
+
data.tar.gz: eed898aa9c21926478716b8286223bbb93094bfb41e5b9e6f6c11e0c2c4c051f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de04120c184bd5652d8477c061b7798f0bde11d732b4392f0c945abe94c7a61c2bcb9ae32f3b5609dc3eb3583dda5d4751677f4a6dd2b3fe2ae92c8283400793
|
7
|
+
data.tar.gz: ef85c7981c451c107379b11d753d5e5dd8ca0d188dbbfd7bcb8f4b548ae81896ecd75ae1f7264bd6ec242263ba865205d30cca030231a60d7972bf1babd31ced
|
@@ -54,34 +54,53 @@ class Unidom::Geo::China::Region < Unidom::Geo::China::ApplicationRecord
|
|
54
54
|
numeric_code[0..1]
|
55
55
|
end
|
56
56
|
|
57
|
+
##
|
58
|
+
# 获取行政区划代码的中间 2 位数字。
|
57
59
|
def numeric_code_middle
|
58
60
|
numeric_code[2..3]
|
59
61
|
end
|
60
62
|
|
63
|
+
##
|
64
|
+
# 获取行政区划代码的后 2 位数字。
|
61
65
|
def numeric_code_suffix
|
62
66
|
numeric_code[4..5]
|
63
67
|
end
|
64
68
|
|
69
|
+
##
|
70
|
+
# 判断行政区划代码的中间 2 位数字是否为 00 。
|
65
71
|
def numeric_code_middle_empty?
|
66
72
|
'00'==numeric_code_middle
|
67
73
|
end
|
68
74
|
|
75
|
+
##
|
76
|
+
# 判断行政区划代码的后 2 位数字是否为 00 。
|
69
77
|
def numeric_code_suffix_empty?
|
70
78
|
'00'==numeric_code_suffix
|
71
79
|
end
|
72
80
|
|
81
|
+
##
|
82
|
+
# 判断一个区县级的行政区划是否是区。
|
73
83
|
def district?
|
74
84
|
numeric_code_suffix.to_i<20
|
75
85
|
end
|
76
86
|
|
87
|
+
##
|
88
|
+
# 判断一个行政区划是否是或者属于直辖市。
|
77
89
|
def under_mducg?
|
78
90
|
self.class::MDUCG_CODES.include? numeric_code_prefix
|
79
91
|
end
|
80
92
|
|
93
|
+
##
|
94
|
+
# 判断一个行政区划是否是直辖市。
|
81
95
|
def mducg?
|
82
96
|
under_mducg? && numeric_code_middle_empty? && numeric_code_suffix_empty?
|
83
97
|
end
|
84
98
|
|
99
|
+
##
|
100
|
+
# 拼写当前行政区划的全称,用指定的分隔符区分。如:
|
101
|
+
# region.full_name
|
102
|
+
# # or
|
103
|
+
# region.full_name ' '
|
85
104
|
def full_name(separator = ' ')
|
86
105
|
final_name = self.name
|
87
106
|
current_region = self
|
@@ -8,7 +8,7 @@ class Unidom::Geo::China::Town < Unidom::Geo::China::ApplicationRecord
|
|
8
8
|
include Unidom::Common::Concerns::ModelExtension
|
9
9
|
|
10
10
|
validates :numeric_code, length: { minimum: self.columns_hash['numeric_code'].limit }, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
11
|
-
validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit
|
11
|
+
validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
|
12
12
|
|
13
13
|
belongs_to :region, class_name: 'Unidom::Geo::China::Region'
|
14
14
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomChinaRegions < ActiveRecord::Migration
|
1
|
+
class CreateUnidomChinaRegions < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -16,9 +16,9 @@ class CreateUnidomChinaRegions < ActiveRecord::Migration
|
|
16
16
|
t.text :instruction
|
17
17
|
t.text :description
|
18
18
|
|
19
|
-
t.column :state, 'char(1)', null: false, default:
|
20
|
-
t.datetime :opened_at, null: false, default: ::
|
21
|
-
t.datetime :closed_at, null: false, default: ::
|
19
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
20
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
21
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
22
22
|
t.boolean :defunct, null: false, default: false
|
23
23
|
t.jsonb :notation, null: false, default: {}
|
24
24
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateUnidomChinaTowns < ActiveRecord::Migration
|
1
|
+
class CreateUnidomChinaTowns < ActiveRecord::Migration[6.0]
|
2
2
|
|
3
3
|
def change
|
4
4
|
|
@@ -14,9 +14,9 @@ class CreateUnidomChinaTowns < ActiveRecord::Migration
|
|
14
14
|
t.text :instruction
|
15
15
|
t.text :description
|
16
16
|
|
17
|
-
t.column :state, 'char(1)', null: false, default:
|
18
|
-
t.datetime :opened_at, null: false, default: ::
|
19
|
-
t.datetime :closed_at, null: false, default: ::
|
17
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
18
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
19
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
20
20
|
t.boolean :defunct, null: false, default: false
|
21
21
|
t.jsonb :notation, null: false, default: {}
|
22
22
|
|
@@ -8,6 +8,61 @@ describe Unidom::Geo::China::Region, type: :model do
|
|
8
8
|
after :each do
|
9
9
|
end
|
10
10
|
|
11
|
+
it 'should consider Beijing under a municipality direct under central government' do
|
12
|
+
region = described_class.numeric_coded_as('110000').first_or_initialize
|
13
|
+
expect(region.under_mducg?).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should consider Chaoyang under a municipality direct under central government' do
|
17
|
+
region = described_class.numeric_coded_as('110105').first_or_initialize
|
18
|
+
expect(region.under_mducg?).to be_truthy
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should consider Tainjin under a municipality direct under central government' do
|
22
|
+
region = described_class.numeric_coded_as('120000').first_or_initialize
|
23
|
+
expect(region.under_mducg?).to be_truthy
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should consider Nankai under a municipality direct under central government' do
|
27
|
+
region = described_class.numeric_coded_as('120104').first_or_initialize
|
28
|
+
expect(region.under_mducg?).to be_truthy
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should consider Shanghai under a municipality direct under central government' do
|
32
|
+
region = described_class.numeric_coded_as('310000').first_or_initialize
|
33
|
+
expect(region.under_mducg?).to be_truthy
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should consider Xuhui under a municipality direct under central government' do
|
37
|
+
region = described_class.numeric_coded_as('310104').first_or_initialize
|
38
|
+
expect(region.under_mducg?).to be_truthy
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should consider Chongqing under a municipality direct under central government' do
|
42
|
+
region = described_class.numeric_coded_as('500000').first_or_initialize
|
43
|
+
expect(region.under_mducg?).to be_truthy
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should consider Shapinba under a municipality direct under central government' do
|
47
|
+
region = described_class.numeric_coded_as('500106').first_or_initialize
|
48
|
+
expect(region.under_mducg?).to be_truthy
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not consider Sichuan under a municipality direct under central government' do
|
52
|
+
region = described_class.numeric_coded_as('510000').first_or_initialize
|
53
|
+
expect(region.under_mducg?).to be_falsey
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not consider Chengdu under a municipality direct under central government' do
|
57
|
+
region = described_class.numeric_coded_as('510100').first_or_initialize
|
58
|
+
expect(region.under_mducg?).to be_falsey
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not consider Jinniu under a municipality direct under central government' do
|
62
|
+
region = described_class.numeric_coded_as('510106').first_or_initialize
|
63
|
+
expect(region.under_mducg?).to be_falsey
|
64
|
+
end
|
65
|
+
|
11
66
|
context do
|
12
67
|
|
13
68
|
model_attributes = {
|
@@ -75,6 +130,15 @@ describe Unidom::Geo::China::Region, type: :model do
|
|
75
130
|
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, virtual: true) ], count_diff: 0, args: [ false ] }
|
76
131
|
]
|
77
132
|
|
133
|
+
it_behaves_like 'scope', :root_level, [
|
134
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid ) ], count_diff: 0, args: [] },
|
135
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '999900') ], count_diff: 0, args: [] },
|
136
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '999000') ], count_diff: 0, args: [] },
|
137
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '990000') ], count_diff: 1, args: [] },
|
138
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '900000') ], count_diff: 1, args: [] },
|
139
|
+
{ attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '000000') ], count_diff: 1, args: [] }
|
140
|
+
]
|
141
|
+
|
78
142
|
end
|
79
143
|
|
80
144
|
end
|
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: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-geo
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.5.6
|
19
|
+
version: '2.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.5.6
|
26
|
+
version: '2.0'
|
33
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
34
28
|
The China Contact domain model engine includes Mobile Phone Number and its relative
|
35
29
|
models. Unidom (统一领域对象模型)是一系列的领域模型引擎。中国地理领域模型引擎包括中国大陆的行政区划及其相关的模型。
|
@@ -72,7 +66,7 @@ homepage: https://github.com/topbitdu/unidom-geo-china
|
|
72
66
|
licenses:
|
73
67
|
- MIT
|
74
68
|
metadata: {}
|
75
|
-
post_install_message:
|
69
|
+
post_install_message:
|
76
70
|
rdoc_options: []
|
77
71
|
require_paths:
|
78
72
|
- lib
|
@@ -87,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
81
|
- !ruby/object:Gem::Version
|
88
82
|
version: '0'
|
89
83
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
signing_key:
|
84
|
+
rubygems_version: 3.2.3
|
85
|
+
signing_key:
|
93
86
|
specification_version: 4
|
94
87
|
summary: Unidom China Geo Domain Model Engine 中国地理领域模型引擎
|
95
88
|
test_files: []
|