geo_master_jp 0.1.29 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/app/controllers/geo_master_jp/area_api_controller.rb +0 -4
- data/app/controllers/geo_master_jp/railway_api_controller.rb +96 -0
- data/app/models/geo_master_jp/line.rb +24 -0
- data/app/models/geo_master_jp/prefecture.rb +12 -0
- data/app/models/geo_master_jp/prefectures_line.rb +15 -0
- data/app/models/geo_master_jp/railway_company.rb +14 -0
- data/app/models/geo_master_jp/station.rb +20 -3
- data/config/routes.rb +15 -4
- data/lib/generators/geo_master_jp/install_area_data_generator.rb +4 -4
- data/lib/generators/geo_master_jp/install_migration_generator.rb +4 -1
- data/lib/generators/geo_master_jp/install_railway_data_generator.rb +45 -15
- data/lib/generators/geo_master_jp/templates/create_prefectures_lines.rb.erb +12 -0
- data/lib/generators/geo_master_jp/templates/geo_master_jp.rb +3 -0
- data/lib/geo_master_jp/config.rb +2 -1
- data/lib/geo_master_jp/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e79b95487f5cc5171afc0efc091c33d13d9939833b17a218d2f37adc1c0eb24
|
4
|
+
data.tar.gz: bf967e1b4d4ed2a649aff000f60aed84982fa5b58030ed7ccab8b4073c146dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ca29393e1fc2e6b9c5374c005c1103be2fc8fdfbdbeee9257b3746327d92b03bb1fe2be3dc057222be89a215c9cd45dad2ecc53dd33ba3f06f6c9137da397b
|
7
|
+
data.tar.gz: 4243a30e79e11ad4b9de803115ffd6d28cb06762d299ce6bd00f3ae67c39b68fab683ac4ecaf97cd2baee80196210a52a83fbbd0ae5314aecfd22b02721b090d
|
data/README.md
CHANGED
@@ -74,6 +74,12 @@ Then you can use the following API:
|
|
74
74
|
- `/geo_master_jp/api/prefectures`
|
75
75
|
- `/geo_master_jp/api/cities?prefecture_code=13`
|
76
76
|
- `/geo_master_jp/api/towns?city_code=13104`
|
77
|
+
- `/geo_master_jp/api/railway_companies`
|
78
|
+
- `/geo_master_jp/api/lines?prefecture_code=13`
|
79
|
+
- `/geo_master_jp/api/lines?railway_company_code=002`
|
80
|
+
- `/geo_master_jp/api/stations?line_code=11302`
|
81
|
+
- `/geo_master_jp/api/stations?line_code=11302&prefecture_code=13`
|
82
|
+
- `/geo_master_jp/api/same_stations?same_stations=1130225`
|
77
83
|
|
78
84
|
## Contributing
|
79
85
|
Contribution directions go here.
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module GeoMasterJp
|
2
|
+
class RailwayApiController < ApplicationController
|
3
|
+
def railway_companies
|
4
|
+
railway_companies = GeoMasterJp::RailwayCompany.all
|
5
|
+
|
6
|
+
if params[:status].present?
|
7
|
+
railway_companies = railway_companies.where(status: params[:status].split(','))
|
8
|
+
else
|
9
|
+
railway_companies = railway_companies.where(status: 0)
|
10
|
+
end
|
11
|
+
|
12
|
+
render json: {
|
13
|
+
railway_companies: railway_companies.map{|railway_company|
|
14
|
+
railway_company.as_json(only: [:status, :company_type, :group_code, :code, :name, :name_kana, :name_full, :name_short, :url])
|
15
|
+
},
|
16
|
+
initials: railway_companies.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def lines
|
21
|
+
if params[:prefecture_code].blank? && params[:railway_company_code].blank?
|
22
|
+
return render json: {
|
23
|
+
message: 'prefecture_code or railway_company_code is required.'
|
24
|
+
}, status: 400
|
25
|
+
end
|
26
|
+
|
27
|
+
if params[:prefecture_code].present?
|
28
|
+
lines = GeoMasterJp::Prefecture.find_by(code: params[:prefecture_code]).lines
|
29
|
+
else
|
30
|
+
lines = GeoMasterJp::RailwayCompany.find_by(code: params[:railway_company_code]).lines
|
31
|
+
end
|
32
|
+
|
33
|
+
if params[:status].present?
|
34
|
+
lines = lines.where(status: params[:status].split(','))
|
35
|
+
else
|
36
|
+
lines = lines.where(status: 0)
|
37
|
+
end
|
38
|
+
|
39
|
+
render json: {
|
40
|
+
lines: lines.map{|line|
|
41
|
+
line.as_json(only: [:status, :code, :name, :name_kana, :name_full, :longitude, :latitude, :sort_order])
|
42
|
+
},
|
43
|
+
initials: lines.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def stations
|
48
|
+
if params[:line_code].blank?
|
49
|
+
return render json: {
|
50
|
+
message: 'line_code is required.'
|
51
|
+
}, status: 400
|
52
|
+
end
|
53
|
+
|
54
|
+
stations = GeoMasterJp::Line.find_by(code: params[:line_code]).stations.joins(:station_connections)
|
55
|
+
|
56
|
+
if params[:prefecture_code].present?
|
57
|
+
stations = stations.where(geo_master_jp_prefecture_code: params[:prefecture_code])
|
58
|
+
end
|
59
|
+
|
60
|
+
if params[:status].present?
|
61
|
+
stations = stations.where(status: params[:status].split(','))
|
62
|
+
else
|
63
|
+
stations = stations.where(status: 0)
|
64
|
+
end
|
65
|
+
|
66
|
+
render json: {
|
67
|
+
stations: stations.map{|station|
|
68
|
+
station.as_json(
|
69
|
+
only: [:status, :code, :group_code, :name, :zip_code, :address, :longitude, :latitude, :open_date, :close_date, :sort_order],
|
70
|
+
methods: :neighbor_station_codes,
|
71
|
+
)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def same_stations
|
77
|
+
if params[:station_code].blank?
|
78
|
+
return render json: {
|
79
|
+
message: 'station_code is required.'
|
80
|
+
}, status: 400
|
81
|
+
end
|
82
|
+
|
83
|
+
stations = GeoMasterJp::Station.find_by(code: params[:station_code]).same_stations
|
84
|
+
|
85
|
+
if params[:status].present?
|
86
|
+
stations = stations.where(status: params[:status].to_i)
|
87
|
+
end
|
88
|
+
|
89
|
+
render json: {
|
90
|
+
stations: stations.map{|station|
|
91
|
+
line.as_json(only: [:status, :code, :group_code, :name, :zip_code, :address, :longitude, :latitude, :open_date, :close_date, :sort_order])
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -5,17 +5,41 @@ module GeoMasterJp
|
|
5
5
|
belongs_to :railway_company, class_name: 'GeoMasterJp::RailwayCompany', foreign_key: :geo_master_jp_railway_company_code, primary_key: :code
|
6
6
|
has_many :stations, class_name: 'GeoMasterJp::Station', foreign_key: :geo_master_jp_line_code, primary_key: :code
|
7
7
|
|
8
|
+
if GeoMasterJp.config.use_models.include?(:area)
|
9
|
+
has_many :prefectures_lines, class_name: 'GeoMasterJp::PrefecturesLine', foreign_key: :geo_master_jp_line_code, primary_key: :code
|
10
|
+
has_many :prefectures, through: :prefectures_lines, class_name: 'GeoMasterJp::Prefecture'
|
11
|
+
end
|
12
|
+
|
8
13
|
enum status: {
|
9
14
|
running: 0,
|
10
15
|
will_run: 1,
|
11
16
|
deleted: 2
|
12
17
|
}
|
13
18
|
|
19
|
+
def head_kana
|
20
|
+
return '' if self.name_kana.blank?
|
21
|
+
head_kanas = ['ア', 'カ', 'サ', 'タ', 'ナ', 'ハ', 'マ', 'ヤ', 'ラ', 'ワ']
|
22
|
+
head_kanas[head_kanas.index{|i| i > self.name_kana[0] }.to_i - 1]
|
23
|
+
end
|
24
|
+
|
14
25
|
def self.inherited(child)
|
15
26
|
child.belongs_to :railway_company, class_name: GeoMasterJp.config.alternative_class_name(:railway_company), foreign_key: :geo_master_jp_railway_company_code, primary_key: :code
|
16
27
|
child.has_many :stations, class_name: GeoMasterJp.config.alternative_class_name(:station), foreign_key: :geo_master_jp_line_code, primary_key: :code
|
17
28
|
|
29
|
+
if GeoMasterJp.config.use_models.include?(:area)
|
30
|
+
child.has_many :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:prefectures_line), foreign_key: :geo_master_jp_line_code, primary_key: :code
|
31
|
+
child.has_many :prefectures, through: :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:prefecture)
|
32
|
+
end
|
33
|
+
|
18
34
|
super
|
19
35
|
end
|
36
|
+
|
37
|
+
def station_select_options
|
38
|
+
self.stations.map{|station| [station.name, station.code] }
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.select_options(transactions=nil)
|
42
|
+
(transactions || all).map{|line| [line.name, line.code] }
|
43
|
+
end
|
20
44
|
end
|
21
45
|
end
|
@@ -5,6 +5,12 @@ module GeoMasterJp
|
|
5
5
|
has_many :cities, class_name: 'GeoMasterJp::City', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
6
6
|
has_many :towns, class_name: 'GeoMasterJp::Town', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
7
7
|
|
8
|
+
if GeoMasterJp.config.use_models.include?(:railway)
|
9
|
+
has_many :stations, class_name: 'GeoMasterJp::Station', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
10
|
+
has_many :prefectures_lines, class_name: 'GeoMasterJp::PrefecturesLine', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
11
|
+
has_many :lines, through: :prefectures_lines
|
12
|
+
end
|
13
|
+
|
8
14
|
def head_kana
|
9
15
|
return '' if self.name_kana.blank?
|
10
16
|
head_kanas = ['ア', 'カ', 'サ', 'タ', 'ナ', 'ハ', 'マ', 'ヤ', 'ラ', 'ワ']
|
@@ -15,6 +21,12 @@ module GeoMasterJp
|
|
15
21
|
child.has_many :cities, class_name: GeoMasterJp.config.alternative_class_name(:city), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
16
22
|
child.has_many :towns, class_name: GeoMasterJp.config.alternative_class_name(:town), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
17
23
|
|
24
|
+
if GeoMasterJp.config.use_models.include?(:railway)
|
25
|
+
child.has_many :stations, class_name: GeoMasterJp.config.alternative_class_name(:station), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
26
|
+
child.has_many :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:prefectures_line), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
27
|
+
child.has_many :lines, through: :prefectures_lines, class_name: GeoMasterJp.config.alternative_class_name(:line)
|
28
|
+
end
|
29
|
+
|
18
30
|
super
|
19
31
|
end
|
20
32
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GeoMasterJp
|
2
|
+
class PrefecturesLine < ActiveRecord::Base
|
3
|
+
self.table_name = 'geo_master_jp_prefectures_lines'
|
4
|
+
|
5
|
+
belongs_to :prefecture, class_name: 'GeoMasterJp::Prefecture', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
6
|
+
belongs_to :line, class_name: 'GeoMasterJp::Line', foreign_key: :geo_master_jp_line_code, primary_key: :code
|
7
|
+
|
8
|
+
def self.inherited(child)
|
9
|
+
child.belongs_to :prefecture, class_name: GeoMasterJp.config.alternative_class_name(:prefecture), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
10
|
+
child.belongs_to :line, class_name: GeoMasterJp.config.alternative_class_name(:line), foreign_key: :geo_master_jp_line_code, primary_key: :code
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -10,10 +10,24 @@ module GeoMasterJp
|
|
10
10
|
deleted: 2
|
11
11
|
}
|
12
12
|
|
13
|
+
def head_kana
|
14
|
+
return '' if self.name_kana.blank?
|
15
|
+
head_kanas = ['ア', 'カ', 'サ', 'タ', 'ナ', 'ハ', 'マ', 'ヤ', 'ラ', 'ワ']
|
16
|
+
head_kanas[head_kanas.index{|i| i > self.name_kana[0] }.to_i - 1]
|
17
|
+
end
|
18
|
+
|
13
19
|
def self.inherited(child)
|
14
20
|
child.has_many :lines, class_name: GeoMasterJp.config.alternative_class_name(:line), foreign_key: :geo_master_jp_railway_company_code, primary_key: :code
|
15
21
|
|
16
22
|
super
|
17
23
|
end
|
24
|
+
|
25
|
+
def line_select_options
|
26
|
+
self.lines.map{|line| [line.name, line.code] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.select_options(transactions=nil)
|
30
|
+
(transactions || all).map{|railway_company| [railway_company.name, railway_company.code] }
|
31
|
+
end
|
18
32
|
end
|
19
33
|
end
|
@@ -2,9 +2,14 @@ module GeoMasterJp
|
|
2
2
|
class Station < ActiveRecord::Base
|
3
3
|
self.table_name = 'geo_master_jp_stations'
|
4
4
|
|
5
|
-
belongs_to :line,
|
6
|
-
has_many
|
7
|
-
|
5
|
+
belongs_to :line, class_name: 'GeoMasterJp::Line', foreign_key: :geo_master_jp_line_code, primary_key: :code
|
6
|
+
has_many :same_stations, class_name: 'GeoMasterJp::Station', foreign_key: :group_code, primary_key: :group_code
|
7
|
+
has_many :station_connections, class_name: 'GeoMasterJp::StationConnection', foreign_key: :geo_master_jp_station_1_code, primary_key: :code
|
8
|
+
has_many :neighbors, class_name: 'GeoMasterJp::Station', through: :station_connections, source: :station_2
|
9
|
+
|
10
|
+
if GeoMasterJp.config.use_models.include?(:area)
|
11
|
+
belongs_to :prefecture, class_name: 'GeoMasterJp::Prefecture', foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
12
|
+
end
|
8
13
|
|
9
14
|
enum status: {
|
10
15
|
running: 0,
|
@@ -12,11 +17,23 @@ module GeoMasterJp
|
|
12
17
|
deleted: 2
|
13
18
|
}
|
14
19
|
|
20
|
+
def neighbor_station_codes
|
21
|
+
station_connections.pluck(:geo_master_jp_station_2_code)
|
22
|
+
end
|
23
|
+
|
15
24
|
def self.inherited(child)
|
16
25
|
child.belongs_to :line, class_name: GeoMasterJp.config.alternative_class_name(:line), foreign_key: :geo_master_jp_line_code, primary_key: :code
|
17
26
|
child.has_many :same_stations, class_name: GeoMasterJp.config.alternative_class_name(:station), foreign_key: :group_code, primary_key: :group_code
|
18
27
|
|
28
|
+
if GeoMasterJp.config.use_models.include?(:area)
|
29
|
+
child.belongs_to :prefecture, class_name: GeoMasterJp.config.alternative_class_name(:prefecture), foreign_key: :geo_master_jp_prefecture_code, primary_key: :code
|
30
|
+
end
|
31
|
+
|
19
32
|
super
|
20
33
|
end
|
34
|
+
|
35
|
+
def self.select_options(transactions=nil)
|
36
|
+
(transactions || all).map{|station| [station.name, line.code] }
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
GeoMasterJp::Engine.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
if GeoMasterJp.config.use_apis.include?(:area)
|
3
|
+
scope :api, as: 'api' do
|
4
|
+
get 'prefectures', to: 'area_api#prefectures'
|
5
|
+
get 'cities', to: 'area_api#cities'
|
6
|
+
get 'towns', to: 'area_api#towns'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if GeoMasterJp.config.use_apis.include?(:railway)
|
11
|
+
scope :api, as: 'api' do
|
12
|
+
get 'railway_companies', to: 'railway_api#railway_companies'
|
13
|
+
get 'lines', to: 'railway_api#lines'
|
14
|
+
get 'stations', to: 'railway_api#stations'
|
15
|
+
get 'same_stations', to: 'railway_api#same_stations'
|
16
|
+
end
|
6
17
|
end
|
7
18
|
end
|
@@ -19,7 +19,7 @@ module GeoMasterJp
|
|
19
19
|
return
|
20
20
|
end
|
21
21
|
YAML.load_file("#{__dir__}/data/prefectures.yml").each do |prefecture|
|
22
|
-
GeoMasterJp::Prefecture.create(prefecture)
|
22
|
+
GeoMasterJp::Prefecture.create!(prefecture)
|
23
23
|
end
|
24
24
|
|
25
25
|
puts "Set Prefecture is complete."
|
@@ -45,13 +45,13 @@ module GeoMasterJp
|
|
45
45
|
if town_rows[0][26] == '2' # 変更
|
46
46
|
city = set_city(city, town_rows[0])
|
47
47
|
|
48
|
-
city.save
|
48
|
+
city.save!
|
49
49
|
end
|
50
50
|
else # 新規
|
51
51
|
city = prefecture.cities.build(code: city_code)
|
52
52
|
city = set_city(city, town_rows[0])
|
53
53
|
|
54
|
-
city.save
|
54
|
+
city.save!
|
55
55
|
end
|
56
56
|
|
57
57
|
towns[city.code] = []
|
@@ -63,7 +63,7 @@ module GeoMasterJp
|
|
63
63
|
town = set_town(town, row)
|
64
64
|
town.city = city
|
65
65
|
|
66
|
-
town.save
|
66
|
+
town.save!
|
67
67
|
elsif town_row[26] == '3' # 廃止
|
68
68
|
town.update!(deleted_at: Time.current)
|
69
69
|
end
|
@@ -17,11 +17,14 @@ module GeoMasterJp
|
|
17
17
|
def create_migration_file
|
18
18
|
templates = ['create_versions']
|
19
19
|
if GeoMasterJp.config.use_models.include?(:area)
|
20
|
-
templates += ['create_prefectures', 'create_cities', 'create_towns'
|
20
|
+
templates += ['create_prefectures', 'create_cities', 'create_towns']
|
21
21
|
end
|
22
22
|
if GeoMasterJp.config.use_models.include?(:railway)
|
23
23
|
templates += ['create_prefectures', 'create_cities', 'create_towns', 'create_railway_companies', 'create_lines', 'create_stations', 'create_station_connections']
|
24
24
|
end
|
25
|
+
if GeoMasterJp.config.use_models.include?(:area) && GeoMasterJp.config.use_models.include?(:railway)
|
26
|
+
templates += ['create_prefectures_lines']
|
27
|
+
end
|
25
28
|
|
26
29
|
migration_dir = File.expand_path("db/migrate")
|
27
30
|
templates.each do |template|
|
@@ -24,7 +24,7 @@ module GeoMasterJp
|
|
24
24
|
csv_data.each do |row|
|
25
25
|
railway_company = GeoMasterJp::RailwayCompany.find_by(code: format('%03d', row[0].to_i)) || GeoMasterJp::RailwayCompany.new
|
26
26
|
railway_company = set_railway_company(railway_company, row)
|
27
|
-
railway_company.save
|
27
|
+
railway_company.save!
|
28
28
|
end
|
29
29
|
|
30
30
|
GeoMasterJp::Version.create!(model_name_string: GeoMasterJp::RailwayCompany.to_s, version: Date.parse(RAILWAY_COMPANY_VERSION))
|
@@ -48,7 +48,7 @@ module GeoMasterJp
|
|
48
48
|
rows.each do |row|
|
49
49
|
line = GeoMasterJp::Line.find_by(code: format('%05d', row[0].to_i)) || railway_company.lines.build
|
50
50
|
line = set_line(line, row)
|
51
|
-
line.save
|
51
|
+
line.save!
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -73,7 +73,7 @@ module GeoMasterJp
|
|
73
73
|
rows.each do |row|
|
74
74
|
station = GeoMasterJp::Station.find_by(code: format('%07d', row[0].to_i)) || line.stations.build
|
75
75
|
station = set_station(station, row)
|
76
|
-
station.save
|
76
|
+
station.save!
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -89,25 +89,31 @@ module GeoMasterJp
|
|
89
89
|
return
|
90
90
|
end
|
91
91
|
|
92
|
+
# 接続にはステータスがないため、全削除して再登録
|
93
|
+
GeoMasterJp::StationConnection.delete_all
|
94
|
+
|
92
95
|
csv_data = get_railway_data("join#{STATION_CONNECTION_VERSION}.csv")
|
93
96
|
|
94
97
|
csv_data_each_line_code = csv_data.group_by{|row| format('%05d', row[0].to_i)}
|
95
98
|
csv_data_each_line_code.each_with_index do |(line_code, rows), idx|
|
96
99
|
print "Setting StationConnection ...#{idx+1}/#{csv_data_each_line_code.count}\r"
|
97
100
|
|
98
|
-
line = GeoMasterJp::Line.find_by(code: line_code)
|
99
101
|
rows.each do |row|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
next if
|
104
|
-
|
105
|
-
station_connection = GeoMasterJp::StationConnection.new
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
station_connection.
|
102
|
+
station_1_code = format('%07d', row[1].to_i)
|
103
|
+
station_2_code = format('%07d', row[2].to_i)
|
104
|
+
|
105
|
+
next if GeoMasterJp::Station.find_by(code: station_1_code).blank? || GeoMasterJp::Station.find_by(code: station_2_code).blank?
|
106
|
+
|
107
|
+
station_connection = GeoMasterJp::StationConnection.new(
|
108
|
+
geo_master_jp_line_code: line_code,
|
109
|
+
geo_master_jp_station_1_code: station_1_code,
|
110
|
+
geo_master_jp_station_2_code: station_2_code,
|
111
|
+
).save!
|
112
|
+
station_connection = GeoMasterJp::StationConnection.new(
|
113
|
+
geo_master_jp_line_code: line_code,
|
114
|
+
geo_master_jp_station_1_code: station_2_code,
|
115
|
+
geo_master_jp_station_2_code: station_1_code,
|
116
|
+
).save!
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
@@ -117,6 +123,30 @@ module GeoMasterJp
|
|
117
123
|
puts "Set StationConnection is complete."
|
118
124
|
end
|
119
125
|
|
126
|
+
def set_prefectures_lines
|
127
|
+
return unless GeoMasterJp.config.use_models.include?(:area)
|
128
|
+
if GeoMasterJp::Prefecture.count == 0
|
129
|
+
puts "PrefectureLines is skipped as Prefecture is not imported."
|
130
|
+
return
|
131
|
+
end
|
132
|
+
|
133
|
+
if GeoMasterJp::Version.last_version('GeoMasterJp::PrefecturesLine').present? && GeoMasterJp::Version.last_version(GeoMasterJp::Line) >= Date.parse(LINE_VERSION)
|
134
|
+
puts "PrefectureLines is already latest version and skip."
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
GeoMasterJp::Line.all.each_with_index do |line, idx|
|
139
|
+
print "Setting PrefecturesLine ...#{idx+1}/#{GeoMasterJp::Line.count}\r"
|
140
|
+
prefecture_codes = line.stations.group(:geo_master_jp_prefecture_code).pluck(:geo_master_jp_prefecture_code)
|
141
|
+
prefecture_codes.each {|prefecture_code| line.prefectures_lines.create(geo_master_jp_prefecture_code: prefecture_code)}
|
142
|
+
end
|
143
|
+
|
144
|
+
GeoMasterJp::Version.create!(model_name_string: 'GeoMasterJp::PrefecturesLine', version: Date.parse(LINE_VERSION))
|
145
|
+
|
146
|
+
print "\n"
|
147
|
+
puts "Set PrefecturesLine is complete."
|
148
|
+
end
|
149
|
+
|
120
150
|
private
|
121
151
|
|
122
152
|
def set_railway_company(railway_company, row)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreatePrefecturesLines < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :geo_master_jp_prefectures_lines do |t|
|
4
|
+
t.string :geo_master_jp_line_code, null: false, index: true, foreign_key: true
|
5
|
+
t.string :geo_master_jp_prefecture_code, null: false, index: true, foreign_key: true
|
6
|
+
|
7
|
+
t.timestamps index: true
|
8
|
+
end
|
9
|
+
add_foreign_key :geo_master_jp_prefectures_lines, :geo_master_jp_lines, column: :geo_master_jp_line_code, primary_key: :code
|
10
|
+
add_foreign_key :geo_master_jp_prefectures_lines, :geo_master_jp_prefectures, column: :geo_master_jp_prefecture_code, primary_key: :code
|
11
|
+
end
|
12
|
+
end
|
@@ -13,6 +13,9 @@ GeoMasterJp.configure do |config|
|
|
13
13
|
# Use Models
|
14
14
|
# config.use_models = [:area, :railway]
|
15
15
|
|
16
|
+
# Use APIs
|
17
|
+
# config.use_apis = [:area, :railway]
|
18
|
+
|
16
19
|
# API Filters
|
17
20
|
# config.api.prefectures_filter = ->(prefectures) {
|
18
21
|
# prefecture_codes = ['11', '12', '13', '14']
|
data/lib/geo_master_jp/config.rb
CHANGED
@@ -9,11 +9,12 @@ module GeoMasterJp
|
|
9
9
|
|
10
10
|
class Config
|
11
11
|
# Variables detail is writen in lib/generators/templates/geo_master_jp.rb.
|
12
|
-
attr_accessor :alternative_class_names, :use_models, :api
|
12
|
+
attr_accessor :alternative_class_names, :use_models, :use_apis, :api
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@alternative_class_names = {}
|
16
16
|
@use_models = [:area, :railway]
|
17
|
+
@use_apis = [:area, :railway]
|
17
18
|
@api = API.new
|
18
19
|
end
|
19
20
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_master_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
@@ -92,9 +92,11 @@ files:
|
|
92
92
|
- Rakefile
|
93
93
|
- app/controllers/geo_master_jp/application_controller.rb
|
94
94
|
- app/controllers/geo_master_jp/area_api_controller.rb
|
95
|
+
- app/controllers/geo_master_jp/railway_api_controller.rb
|
95
96
|
- app/models/geo_master_jp/city.rb
|
96
97
|
- app/models/geo_master_jp/line.rb
|
97
98
|
- app/models/geo_master_jp/prefecture.rb
|
99
|
+
- app/models/geo_master_jp/prefectures_line.rb
|
98
100
|
- app/models/geo_master_jp/railway_company.rb
|
99
101
|
- app/models/geo_master_jp/station.rb
|
100
102
|
- app/models/geo_master_jp/station_connection.rb
|
@@ -113,6 +115,7 @@ files:
|
|
113
115
|
- lib/generators/geo_master_jp/templates/create_cities.rb.erb
|
114
116
|
- lib/generators/geo_master_jp/templates/create_lines.rb.erb
|
115
117
|
- lib/generators/geo_master_jp/templates/create_prefectures.rb.erb
|
118
|
+
- lib/generators/geo_master_jp/templates/create_prefectures_lines.rb.erb
|
116
119
|
- lib/generators/geo_master_jp/templates/create_railway_companies.rb.erb
|
117
120
|
- lib/generators/geo_master_jp/templates/create_station_connections.rb.erb
|
118
121
|
- lib/generators/geo_master_jp/templates/create_stations.rb.erb
|