select_city 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/data/eg.png ADDED
Binary file
@@ -0,0 +1,177 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "provinceID": 100000,
5
+ "province": "省/直辖市"
6
+ },
7
+ {
8
+ "id": 2,
9
+ "provinceID": 110000,
10
+ "province": "北京市"
11
+ },
12
+ {
13
+ "id": 3,
14
+ "provinceID": 120000,
15
+ "province": "天津市"
16
+ },
17
+ {
18
+ "id": 4,
19
+ "provinceID": 130000,
20
+ "province": "河北省"
21
+ },
22
+ {
23
+ "id": 5,
24
+ "provinceID": 140000,
25
+ "province": "山西省"
26
+ },
27
+ {
28
+ "id": 6,
29
+ "provinceID": 150000,
30
+ "province": "内蒙古自治区"
31
+ },
32
+ {
33
+ "id": 7,
34
+ "provinceID": 210000,
35
+ "province": "辽宁省"
36
+ },
37
+ {
38
+ "id": 8,
39
+ "provinceID": 220000,
40
+ "province": "吉林省"
41
+ },
42
+ {
43
+ "id": 9,
44
+ "provinceID": 230000,
45
+ "province": "黑龙江省"
46
+ },
47
+ {
48
+ "id": 10,
49
+ "provinceID": 310000,
50
+ "province": "上海市"
51
+ },
52
+ {
53
+ "id": 11,
54
+ "provinceID": 320000,
55
+ "province": "江苏省"
56
+ },
57
+ {
58
+ "id": 12,
59
+ "provinceID": 330000,
60
+ "province": "浙江省"
61
+ },
62
+ {
63
+ "id": 13,
64
+ "provinceID": 340000,
65
+ "province": "安徽省"
66
+ },
67
+ {
68
+ "id": 14,
69
+ "provinceID": 350000,
70
+ "province": "福建省"
71
+ },
72
+ {
73
+ "id": 15,
74
+ "provinceID": 360000,
75
+ "province": "江西省"
76
+ },
77
+ {
78
+ "id": 16,
79
+ "provinceID": 370000,
80
+ "province": "山东省"
81
+ },
82
+ {
83
+ "id": 17,
84
+ "provinceID": 410000,
85
+ "province": "河南省"
86
+ },
87
+ {
88
+ "id": 18,
89
+ "provinceID": 420000,
90
+ "province": "湖北省"
91
+ },
92
+ {
93
+ "id": 19,
94
+ "provinceID": 430000,
95
+ "province": "湖南省"
96
+ },
97
+ {
98
+ "id": 20,
99
+ "provinceID": 440000,
100
+ "province": "广东省"
101
+ },
102
+ {
103
+ "id": 21,
104
+ "provinceID": 450000,
105
+ "province": "广西壮族自治区"
106
+ },
107
+ {
108
+ "id": 22,
109
+ "provinceID": 460000,
110
+ "province": "海南省"
111
+ },
112
+ {
113
+ "id": 23,
114
+ "provinceID": 500000,
115
+ "province": "重庆市"
116
+ },
117
+ {
118
+ "id": 24,
119
+ "provinceID": 510000,
120
+ "province": "四川省"
121
+ },
122
+ {
123
+ "id": 25,
124
+ "provinceID": 520000,
125
+ "province": "贵州省"
126
+ },
127
+ {
128
+ "id": 26,
129
+ "provinceID": 530000,
130
+ "province": "云南省"
131
+ },
132
+ {
133
+ "id": 27,
134
+ "provinceID": 540000,
135
+ "province": "西藏自治区"
136
+ },
137
+ {
138
+ "id": 28,
139
+ "provinceID": 610000,
140
+ "province": "陕西省"
141
+ },
142
+ {
143
+ "id": 29,
144
+ "provinceID": 620000,
145
+ "province": "甘肃省"
146
+ },
147
+ {
148
+ "id": 30,
149
+ "provinceID": 630000,
150
+ "province": "青海省"
151
+ },
152
+ {
153
+ "id": 31,
154
+ "provinceID": 640000,
155
+ "province": "宁夏回族自治区"
156
+ },
157
+ {
158
+ "id": 32,
159
+ "provinceID": 650000,
160
+ "province": "新疆维吾尔自治区"
161
+ },
162
+ {
163
+ "id": 33,
164
+ "provinceID": 710000,
165
+ "province": "台湾省"
166
+ },
167
+ {
168
+ "id": 34,
169
+ "provinceID": 810000,
170
+ "province": "香港特别行政区"
171
+ },
172
+ {
173
+ "id": 35,
174
+ "provinceID": 820000,
175
+ "province": "澳门特别行政区"
176
+ }
177
+ ]
@@ -0,0 +1,4 @@
1
+ module SelectCity
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SelectCity
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,55 @@
1
+ require "select_city/version"
2
+ require "select_city/engine"
3
+ require "json"
4
+
5
+ module SelectCity
6
+ # Your code goes here...
7
+ class << self
8
+ def list(parent_id = nil)
9
+ result = []
10
+ data
11
+ result
12
+ end
13
+
14
+
15
+ def province_list(pid = 100000)
16
+ @list = {}
17
+ provinces.each do |province|
18
+ @list[province["provinceID"]] = province["province"]
19
+ end
20
+ @list
21
+ end
22
+
23
+ def city_list(code = 100000)
24
+ @list = {"''"=>"城市/乡镇"}
25
+ citys.find_all {|k| k["provinceID"] == code }.map do | city |
26
+ @list[city["cityID"]] = city["city"]
27
+ end
28
+ @list
29
+ end
30
+
31
+ def districty_list(code = nil)
32
+ @list = {}
33
+ citys.find_all { |e| e["provinceID"].to_s == code }.map do |city|
34
+ @list[city["cityID"]] = city["city"]
35
+ end
36
+ @list
37
+ end
38
+
39
+ private
40
+
41
+ def city_path
42
+ File.join(File.dirname(__FILE__), '../data')
43
+ end
44
+
45
+ def citys
46
+ json = JSON.parse(File.read("#{city_path}/city.json"))
47
+ end
48
+
49
+ def provinces
50
+ json = JSON.parse(File.read("#{city_path}/province.json"))
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'select_city/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "select_city"
8
+ spec.version = SelectCity::VERSION
9
+ spec.authors = ["wangmingle"]
10
+ spec.email = ["wangmingle@jazznet.cn"]
11
+
12
+ spec.summary = "a gem used for select_option"
13
+ spec.description = "a gem used for select_option"
14
+ spec.homepage = "https://github.com/wangmingle/select_city"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: select_city
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wangmingle
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: a gem used for select_option
42
+ email:
43
+ - wangmingle@jazznet.cn
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/assets/javascripts/select_city.js
55
+ - app/controllers/selectcity_controller.rb
56
+ - bin/console
57
+ - bin/setup
58
+ - config/routes.rb
59
+ - data/city.json
60
+ - data/eg.png
61
+ - data/province.json
62
+ - lib/select_city.rb
63
+ - lib/select_city/engine.rb
64
+ - lib/select_city/version.rb
65
+ - select_city.gemspec
66
+ homepage: https://github.com/wangmingle/select_city
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: a gem used for select_option
90
+ test_files: []
91
+ has_rdoc: