gtfs-engine 1.0.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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +37 -0
  3. data/app/controllers/gtfs_engine/agencies_controller.rb +24 -0
  4. data/app/controllers/gtfs_engine/application_controller.rb +21 -0
  5. data/app/controllers/gtfs_engine/calendar_dates_controller.rb +22 -0
  6. data/app/controllers/gtfs_engine/calendars_controller.rb +51 -0
  7. data/app/controllers/gtfs_engine/data_sets_controller.rb +47 -0
  8. data/app/controllers/gtfs_engine/fare_attributes_controller.rb +27 -0
  9. data/app/controllers/gtfs_engine/fare_rules_controller.rb +26 -0
  10. data/app/controllers/gtfs_engine/feed_infos_controller.rb +26 -0
  11. data/app/controllers/gtfs_engine/frequencies_controller.rb +26 -0
  12. data/app/controllers/gtfs_engine/routes_controller.rb +25 -0
  13. data/app/controllers/gtfs_engine/shapes_controller.rb +23 -0
  14. data/app/controllers/gtfs_engine/stop_times_controller.rb +28 -0
  15. data/app/controllers/gtfs_engine/stops_controller.rb +30 -0
  16. data/app/controllers/gtfs_engine/transfers_controller.rb +38 -0
  17. data/app/controllers/gtfs_engine/trips_controller.rb +34 -0
  18. data/app/helpers/gtfs_engine/default_views_helper.rb +42 -0
  19. data/app/helpers/gtfs_engine/fields_helper.rb +32 -0
  20. data/app/models/gtfs_engine/agency.rb +19 -0
  21. data/app/models/gtfs_engine/calendar.rb +78 -0
  22. data/app/models/gtfs_engine/calendar_date.rb +20 -0
  23. data/app/models/gtfs_engine/data_set.rb +73 -0
  24. data/app/models/gtfs_engine/fare_attribute.rb +19 -0
  25. data/app/models/gtfs_engine/fare_rule.rb +28 -0
  26. data/app/models/gtfs_engine/feed_info.rb +19 -0
  27. data/app/models/gtfs_engine/frequency.rb +20 -0
  28. data/app/models/gtfs_engine/route.rb +24 -0
  29. data/app/models/gtfs_engine/shape.rb +20 -0
  30. data/app/models/gtfs_engine/stop.rb +26 -0
  31. data/app/models/gtfs_engine/stop_time.rb +21 -0
  32. data/app/models/gtfs_engine/transfer.rb +23 -0
  33. data/app/models/gtfs_engine/trip.rb +27 -0
  34. data/app/views/gtfs_engine/calendars/dates.json.jbuilder +18 -0
  35. data/app/views/gtfs_engine/data_sets/index.json.jbuilder +28 -0
  36. data/app/views/gtfs_engine/data_sets/show.json.jbuilder +21 -0
  37. data/app/views/gtfs_engine/gtfs/index.json.jbuilder +15 -0
  38. data/app/views/gtfs_engine/gtfs/show.json.jbuilder +15 -0
  39. data/app/views/gtfs_engine/transfers/from.json.jbuilder +15 -0
  40. data/app/views/gtfs_engine/transfers/from_to.json.jbuilder +15 -0
  41. data/app/views/gtfs_engine/transfers/to.json.jbuilder +15 -0
  42. data/app/views/gtfs_engine/trips/block.json.jbuilder +15 -0
  43. data/bin/rails +8 -0
  44. data/config/initializers/extensions_loader.rb +15 -0
  45. data/config/routes.rb +45 -0
  46. data/db/migrate/20140320045108_create_gtfs_engine_data_sets.rb +17 -0
  47. data/db/migrate/20140320045232_create_gtfs_engine_calendars.rb +24 -0
  48. data/db/migrate/20140320045751_create_gtfs_engine_calendar_dates.rb +16 -0
  49. data/db/migrate/20140320050100_create_gtfs_engine_shapes.rb +20 -0
  50. data/db/migrate/20140320051140_create_gtfs_engine_routes.rb +22 -0
  51. data/db/migrate/20140320052005_create_gtfs_engine_stops.rb +28 -0
  52. data/db/migrate/20140320052508_create_gtfs_engine_trips.rb +26 -0
  53. data/db/migrate/20140320052907_create_gtfs_engine_stop_times.rb +24 -0
  54. data/db/migrate/20140401032609_create_gtfs_engine_agencies.rb +19 -0
  55. data/db/migrate/20140405235947_create_gtfs_engine_fare_attributes.rb +18 -0
  56. data/db/migrate/20140406063500_create_gtfs_engine_fare_rules.rb +17 -0
  57. data/db/migrate/20140406071922_create_gtfs_engine_frequencies.rb +17 -0
  58. data/db/migrate/20140406072309_create_gtfs_engine_transfers.rb +17 -0
  59. data/db/migrate/20140406073548_create_gtfs_engine_feed_infos.rb +16 -0
  60. data/lib/ext.rb +19 -0
  61. data/lib/ext/active_record/associations/association.rb +41 -0
  62. data/lib/gtfs_engine.rb +33 -0
  63. data/lib/gtfs_engine/concerns.rb +19 -0
  64. data/lib/gtfs_engine/concerns/controllers.rb +20 -0
  65. data/lib/gtfs_engine/concerns/controllers/data_access.rb +31 -0
  66. data/lib/gtfs_engine/concerns/controllers/gtfs.rb +158 -0
  67. data/lib/gtfs_engine/engine.rb +28 -0
  68. data/lib/gtfs_engine/exceptions.rb +35 -0
  69. data/lib/gtfs_engine/json_responder.rb +31 -0
  70. data/lib/gtfs_engine/sources.rb +86 -0
  71. data/lib/gtfs_engine/version.rb +84 -0
  72. data/lib/tasks/gtfs_engine_tasks.rake +89 -0
  73. metadata +242 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 830e0c6becf8baf9672f34d694c00bbfc3e0e9b5
4
+ data.tar.gz: 10bc0a9c2e64bca269de14119dbef25e4302ffe4
5
+ SHA512:
6
+ metadata.gz: c5ab00b916477bf5eb06d0b9f442a671863f7793e9253125ca4b0b937d84a2f09e145da3bbea962f0bd59edce4e41d51da4f9040905abdad301c4292bb248690
7
+ data.tar.gz: 7b228fdd219e090ff9f5f76f78854337cceaa8341de82e84bef16e4937ca7e414cb977554d7896ac086b5311211f1ecb826a92f8dcd969984f21a94527fc19a6
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'jeweler'
9
+ require File.dirname(__FILE__) + '/lib/gtfs_engine/version'
10
+
11
+ Jeweler::Tasks.new do |gem|
12
+ gem.name = 'gtfs-engine'
13
+ gem.version = GtfsEngine::Version.to_s
14
+ gem.homepage = 'http://github.com/sangster/gtfs-engine'
15
+ gem.license = 'GPL 3'
16
+ gem.summary = 'Read General Transit Feed Specification zip files'
17
+ gem.description = <<-EOF.strip.gsub /\s+/, ' '
18
+ Reads and parses zip files conforming to Google's GTFS spec.
19
+
20
+ GTFS Spec: https://developers.google.com/transit/gtfs
21
+ EOF
22
+ gem.email = 'jon@ertt.ca'
23
+ gem.authors = ['Jon Sangster']
24
+
25
+ gem.files = Dir['{app,config,db,lib}/**/*', 'Rakefile']
26
+ end
27
+
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ task bump: ['bump:patch']
31
+ namespace :bump do
32
+ %i[major minor patch].each do |part|
33
+ bumper = GtfsEngine::Version::Bumper.new part
34
+ desc "Bump the version to #{bumper}"
35
+ task(part) { bumper.bump }
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class AgenciesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ filters :agency_name,
20
+ :agency_url,
21
+ :agency_timezone,
22
+ :agency_lang
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class ApplicationController < ActionController::Base
17
+ include Concerns::Controllers::DataAccess
18
+ respond_to :json
19
+ self.responder = GtfsEngine::JsonResponder
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class CalendarDatesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+ gtfs_id :service_id
19
+ filters :date,
20
+ :exception_type
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class CalendarsController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ gtfs_id :service_id
20
+
21
+ filters :monday,
22
+ :tuesday,
23
+ :wednesday,
24
+ :thursday,
25
+ :friday,
26
+ :saturday,
27
+ :sunday,
28
+ :start_date,
29
+ :end_date
30
+
31
+ def for_date
32
+ date = params[:YYYY_MM_DD]
33
+ check_format! date
34
+ @records = Calendar.from_date_string date
35
+ respond_with @records, template: 'gtfs_engine/gtfs/index'
36
+ end
37
+
38
+ def dates
39
+ @dates = record.dates
40
+ render :dates
41
+ end
42
+
43
+ private
44
+
45
+ def check_format!(date_str)
46
+ unless %r{^\d{4}-\d\d-\d\d$} === date_str
47
+ raise DateFormatError, "Got '#{date_str}. Expected format: YYYY-MM-DD'"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class DataSetsController < ApplicationController
17
+ def index
18
+ expires_in 3.hours
19
+
20
+ @data_sets = Rails.cache.fetch('data_sets_index') do
21
+ {}.tap do |sets|
22
+ DataSet.order(:created_at).each do |set|
23
+ (sets[set.name] ||= []) << set
24
+ end
25
+ end
26
+ end
27
+
28
+ dates = @data_sets.values.flatten.collect &:created_at
29
+ if stale? last_modified: dates.max, public: true
30
+ respond_with @data_sets
31
+ end
32
+ end
33
+
34
+ def show
35
+ expires_in 2.hours
36
+
37
+ @data_set = data :id
38
+
39
+ # Set location if the given id is a data-source name and not an ID
40
+ if param_is_data_set_name? :id
41
+ respond_with @data_set, location: data_set_url(@data_set)
42
+ else
43
+ respond_with @data_set
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class FareAttributesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ gtfs_id :fare_id
20
+
21
+ filters :price,
22
+ :currency_type,
23
+ :payment_method,
24
+ :transfers,
25
+ :transfer_duration
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class FareRulesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ gtfs_id :fare_id
20
+
21
+ filters :route_id,
22
+ :origin_id,
23
+ :destination_id,
24
+ :contains_id
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class FeedInfosController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ filters :feed_publisher_name,
20
+ :feed_publisher_url,
21
+ :feed_lang,
22
+ :feed_start_date,
23
+ :feed_end_date,
24
+ :feed_version
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class FrequenciesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ gtfs_id :trip_id
20
+
21
+ filters :start_time,
22
+ :end_time,
23
+ :headway_secs,
24
+ :exact_times
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class RoutesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ filters :agency_id,
20
+ :route_short_name,
21
+ :route_long_name,
22
+ :route_type,
23
+ :agency
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class ShapesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ filters :shape_pt_lat,
20
+ :shape_pt_lon,
21
+ :shape_pt_sequence
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class StopTimesController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ gtfs_id :route_id
20
+
21
+ filters :arrival_time,
22
+ :departure_time,
23
+ :stop_sequence,
24
+ :stop_headsign,
25
+ :pickup_type,
26
+ :drop_off_type
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # This file is part of the KNOWtime server.
2
+ #
3
+ # The KNOWtime server is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation, either version 3 of the License, or (at your option) any
6
+ # later version.
7
+ #
8
+ # The KNOWtime server is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11
+ # details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with the KNOWtime server. If not, see <http://www.gnu.org/licenses/>.
15
+ module GtfsEngine
16
+ class StopsController < ApplicationController
17
+ include Concerns::Controllers::Gtfs
18
+
19
+ filters :stop_code,
20
+ :stop_name,
21
+ :stop_desc,
22
+ :stop_lat,
23
+ :stop_lon,
24
+ :zone_id,
25
+ :location_type,
26
+ :parent_station,
27
+ :stop_timezone,
28
+ :wheelchair_boarding
29
+ end
30
+ end