Project

gtfs-orm

0.0
No commit activity in last 3 years
No release in over 3 years
GTFS -> Ruby Object Mapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 10.1.1

Runtime

~> 1.0.1
 Project Readme

About

A Ruby Object Mapper for the Google Transit Feed Specification

Installation

Add this line to your application's Gemfile:

  gem "gtfs-orm", require: "gtfs/orm"

And then execute:

  $ bundle

Or install it yourself as:

  $ gem install gtfs

Resources

GTFS ORM provides Ruby Object Mappings for the General Transit Feed Specification. Each file within a GTFS feed is treated as a model. As of the current revision of the GTFS spec published on June 20, 2012 the following resources are provided:

  • Agency
  • Stop
  • Route
  • Trip
  • StopTime
  • Calendar
  • CalendarDates
  • FareAttribute
  • FareRule
  • Shape
  • Frequency
  • Transfer
  • FeedInfo

API

The Resource API was designed to mirror that of ActiveRecord. Common methods for returning and scoping a Collection (or returning a single Resource) will be familiar to users or Rails, and are implemented as follows:

  • Resource#first (returns the first instance of the collection)
  • Resource#last (returns the last instance of the collection)
  • Resource#all (returns the collection)
  • Resource#where (scopes the collection to resources where the specified conditions apply)
  • Resource#limit (limits the number of resources returned)
  • Resource#page (returns the next group of resources specified by limit)

API Examples

The Resource GTFS::ORM::Agency will be used for the following examples:

Resource#first:

GTFS::ORM::Agency.first
#=> #<GTFS::ORM::Agency:0x007f8d428f0418>

Resource#last:

GTFS::ORM::Agency.last
#=> #<GTFS::ORM::Agency:0x007f8d428f0418>

Resource#all:

GTFS::ORM::Agency.all
#=> [ #<GTFS::ORM::Agency:0x007f8d428f0418>, #<GTFS::ORM::Agency:0x006d8d4281fas98>... ]

Resource#where:

scope = GTFS::ORM::Agency.where(agency_id: 'METRO')
#=> #<GTFS::ORM::Resource::Scope:0x007f8d42932098>
scope.all
#=> [ #<GTFS::ORM::Agency:0x007f8d428f0418>, #<GTFS::ORM::Agency:0x006d8d4281fas98>... ]

Resource#limit:

scope = GTFS::ORM::Agency.limit(2)
#=> #<GTFS::ORM::Resource::Scope:0x007f8d42932098>
scope.all
#=> [ #<GTFS::ORM::Agency:0x007f8d428f0418>, #<GTFS::ORM::Agency:0x006d8d4281fas98> ]

Resource#page:

scope = GTFS::ORM::Agency.page(2)
#=> #<GTFS::ORM::Resource::Scope:0x007f8d42932098>
scope.all
#=> [ #<GTFS::ORM::Agency:0x007f8d428f0418>, #<GTFS::ORM::Agency:0x006d8d4281fas98> ]

Usage

GTFS ORM relies upon the existence of an uncompressed GTFS dir. In order to specify the path, the following configuration must be run before attempting to access any Resources.

GTFS.path('/path/to/uncompressed/gtfs/dir')

Once the path has been specified, Resources can be accessed in the following manner.

GTFS::ORM::Route.limit(30).page(2).where(route_long_name: "Indios Verdes - Dr. Gálvez").all
#=> [ #<GTFS::ORM::Route:0x007f8d429f0f70>, #<GTFS::ORM::Route:0x006d8d429f0f70>...]

Each resource also has a number of associations (as referenced in the GTFS spec linked to above):

agency = GTFS::ORM::Agency.first
agency.routes.first
#=> #<GTFS::ORM::Route:0x007f8d429f0f70>

Contributing

  1. Fork it ( http://github.com//gtfs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request