geo_master_jp 0.1.25 → 0.1.26
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.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/app/controllers/geo_master_jp/application_controller.rb +4 -0
- data/app/controllers/geo_master_jp/area_api_controller.rb +48 -0
- data/{lib/geo_master_jp/models → app/models/geo_master_jp}/city.rb +4 -0
- data/{lib/geo_master_jp/models → app/models/geo_master_jp}/prefecture.rb +8 -0
- data/config/routes.rb +7 -0
- data/lib/geo_master_jp/config.rb +8 -0
- data/lib/geo_master_jp/engine.rb +5 -20
- data/lib/geo_master_jp/version.rb +1 -1
- data/lib/geo_master_jp.rb +1 -0
- metadata +13 -10
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/line.rb +0 -0
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/railway_company.rb +0 -0
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/station.rb +0 -0
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/station_connection.rb +0 -0
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/town.rb +0 -0
- /data/{lib/geo_master_jp/models → app/models/geo_master_jp}/version.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 222479be95afab1d7dfa5087907f5a99dcf229a4c35090c0b2dc8ba0fad79ac6
|
4
|
+
data.tar.gz: 9e7a0dfd2ace7c18dc608d2255cf2a6e50b9198a0f1d981865d650ac479674a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a77f5add500810b1e8c5af4645e72f5a420b1a9f2cf2e92682ebbd7636f327b87833c01ae4174e62a9a9efc48d1c7670426bc0bc71ec7e54b88c128f3dad423
|
7
|
+
data.tar.gz: 67e6b73dad5918e49cc8f92889471cbd3521ff7a60e3fa4980fbc9c5a97b7b89d1e4b2911e68b8e7efcda75a3e0081aa6edbd5c04aea6a5c87bfc501a424f813
|
data/README.md
CHANGED
@@ -45,6 +45,34 @@ rails g geo_master_jp:install_area_data
|
|
45
45
|
rails g geo_master_jp:install_railway_data
|
46
46
|
```
|
47
47
|
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
### Use Area Data Examples
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
prefectures = GeoMasterJp::Prefecture.all
|
54
|
+
|
55
|
+
tokyo = prefectures.find_by(code: '13')
|
56
|
+
cities = tokyo.cities
|
57
|
+
|
58
|
+
shinjuku = cities.find_by(code: '13104')
|
59
|
+
towns = shinjuku.towns
|
60
|
+
```
|
61
|
+
|
62
|
+
### Use Area Data API
|
63
|
+
|
64
|
+
Add the following line to your `config/routes.rb`:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
GeoMasterJp.set_routes(self)
|
68
|
+
```
|
69
|
+
|
70
|
+
Then you can use the following API:
|
71
|
+
|
72
|
+
- `/geo_master_jp/api/prefectures`
|
73
|
+
- `/geo_master_jp/api/cities?prefecture_code=13`
|
74
|
+
- `/geo_master_jp/api/towns?city_code=13104`
|
75
|
+
|
48
76
|
## Contributing
|
49
77
|
Contribution directions go here.
|
50
78
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module GeoMasterJp
|
2
|
+
class AreaApiController < ApplicationController
|
3
|
+
def prefectures
|
4
|
+
prefectures = GeoMasterJp::Prefecture.all
|
5
|
+
|
6
|
+
render json: {
|
7
|
+
prefectures: prefectures.map{|prefecture|
|
8
|
+
prefecture.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name])
|
9
|
+
},
|
10
|
+
initials: prefectures.group_by(&:head_kana).sort_by(&:first).to_h
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def cities
|
15
|
+
if params[:prefecture_code].blank?
|
16
|
+
return render json: {
|
17
|
+
message: 'prefecture_code is required.'
|
18
|
+
}, status: 400
|
19
|
+
end
|
20
|
+
|
21
|
+
cities = GeoMasterJp::Prefecture.find_by(code: params[:prefecture_code]).cities
|
22
|
+
|
23
|
+
render json: {
|
24
|
+
cities: cities.map{|city|
|
25
|
+
city.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name])
|
26
|
+
},
|
27
|
+
initials: cities.group_by(&:head_kana).sort_by(&:first).to_h
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def towns
|
32
|
+
if params[:city_code].blank?
|
33
|
+
return render json: {
|
34
|
+
message: 'city_code is required.'
|
35
|
+
}, status: 400
|
36
|
+
end
|
37
|
+
|
38
|
+
towns = GeoMasterJp::City.find_by(code: params[:city_code]).towns
|
39
|
+
|
40
|
+
render json: {
|
41
|
+
towns: towns.map{|town|
|
42
|
+
town.as_json(only: [:zip_code, :code, :name, :name_kana, :name_alphabet, :short_name])
|
43
|
+
},
|
44
|
+
initials: towns.group_by(&:head_kana).sort_by(&:first).to_h
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/config/routes.rb
ADDED
data/lib/geo_master_jp/config.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
module GeoMasterJp
|
2
|
+
def self.config
|
3
|
+
@config ||= GeoMasterJp::Config.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure(&block)
|
7
|
+
yield(config) if block_given?
|
8
|
+
end
|
9
|
+
|
2
10
|
class Config
|
3
11
|
# Variables detail is writen in lib/generators/templates/geo_master_jp.rb.
|
4
12
|
attr_accessor :alternative_class_names, :use_models
|
data/lib/geo_master_jp/engine.rb
CHANGED
@@ -1,27 +1,12 @@
|
|
1
|
-
require 'geo_master_jp/config'
|
2
1
|
module GeoMasterJp
|
3
|
-
|
4
|
-
|
2
|
+
# GeoMasterJp用のroutingを設定する。
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace GeoMasterJp
|
5
5
|
end
|
6
|
-
|
7
|
-
|
8
|
-
yield(config) if block_given?
|
6
|
+
def self.set_routes(rails_router)
|
7
|
+
rails_router.mount Engine, at: '/geo_master_jp'
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
|
-
if GeoMasterJp.config.use_models.include?(:area)
|
13
|
-
require 'geo_master_jp/models/prefecture'
|
14
|
-
require 'geo_master_jp/models/city'
|
15
|
-
require 'geo_master_jp/models/town'
|
16
|
-
end
|
17
|
-
if GeoMasterJp.config.use_models.include?(:railway)
|
18
|
-
require 'geo_master_jp/models/railway_company'
|
19
|
-
require 'geo_master_jp/models/line'
|
20
|
-
require 'geo_master_jp/models/station'
|
21
|
-
require 'geo_master_jp/models/station_connection'
|
22
|
-
end
|
23
|
-
require 'geo_master_jp/models/version'
|
24
|
-
|
25
11
|
require 'active_record'
|
26
12
|
require 'activerecord-import'
|
27
|
-
|
data/lib/geo_master_jp.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_master_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -90,6 +90,17 @@ files:
|
|
90
90
|
- MIT-LICENSE
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
|
+
- app/controllers/geo_master_jp/application_controller.rb
|
94
|
+
- app/controllers/geo_master_jp/area_api_controller.rb
|
95
|
+
- app/models/geo_master_jp/city.rb
|
96
|
+
- app/models/geo_master_jp/line.rb
|
97
|
+
- app/models/geo_master_jp/prefecture.rb
|
98
|
+
- app/models/geo_master_jp/railway_company.rb
|
99
|
+
- app/models/geo_master_jp/station.rb
|
100
|
+
- app/models/geo_master_jp/station_connection.rb
|
101
|
+
- app/models/geo_master_jp/town.rb
|
102
|
+
- app/models/geo_master_jp/version.rb
|
103
|
+
- config/routes.rb
|
93
104
|
- lib/generators/geo_master_jp/data/company20180424.csv.zip
|
94
105
|
- lib/generators/geo_master_jp/data/join20190405.csv.zip
|
95
106
|
- lib/generators/geo_master_jp/data/line20190405free.csv.zip
|
@@ -112,14 +123,6 @@ files:
|
|
112
123
|
- lib/geo_master_jp/association_helper.rb
|
113
124
|
- lib/geo_master_jp/config.rb
|
114
125
|
- lib/geo_master_jp/engine.rb
|
115
|
-
- lib/geo_master_jp/models/city.rb
|
116
|
-
- lib/geo_master_jp/models/line.rb
|
117
|
-
- lib/geo_master_jp/models/prefecture.rb
|
118
|
-
- lib/geo_master_jp/models/railway_company.rb
|
119
|
-
- lib/geo_master_jp/models/station.rb
|
120
|
-
- lib/geo_master_jp/models/station_connection.rb
|
121
|
-
- lib/geo_master_jp/models/town.rb
|
122
|
-
- lib/geo_master_jp/models/version.rb
|
123
126
|
- lib/geo_master_jp/railtie.rb
|
124
127
|
- lib/geo_master_jp/version.rb
|
125
128
|
- lib/tasks/geo_master_jp_tasks.rake
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|