Giter Site home page Giter Site logo

gtfs-orm's Introduction

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::ORM.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

gtfs-orm's People

Contributors

enezhadian avatar

Stargazers

Marcin Nowicki avatar

Watchers

Jakub Gorzelak avatar Thomas Eisenbarth avatar Andy avatar Jan Rietema avatar James Cloos avatar yaniv preiss avatar Frederik Maatz avatar  avatar Semjon Molokanov avatar Maryam Bahrami avatar Julian avatar Evgeniy Shizgal avatar Alexander Mai avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.