Skip to content

Commit

Permalink
Merge pull request #26 from nerdEd/feed-info
Browse files Browse the repository at this point in the history
parse feed_info.txt
  • Loading branch information
drewda committed Aug 25, 2015
2 parents 9978d16 + 60fcaba commit da1872e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/gtfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'gtfs/agency'
require 'gtfs/calendar'
require 'gtfs/calendar_date'
require 'gtfs/feed_info'
require 'gtfs/route'
require 'gtfs/shape'
require 'gtfs/stop'
Expand Down
19 changes: 19 additions & 0 deletions lib/gtfs/feed_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module GTFS
class FeedInfo
include GTFS::Model

has_required_attrs :publisher_name, :publisher_url, :lang
has_optional_attrs :start_date, :end_date, :version
attr_accessor *attrs

column_prefix :feed_

collection_name :feed_infos
required_file false
uses_filename 'feed_info.txt'

def self.parse_feed_infos(data, options={})
return parse_models(data, options)
end
end
end
2 changes: 1 addition & 1 deletion lib/gtfs/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Source

ENTITIES = [GTFS::Agency, GTFS::Stop, GTFS::Route, GTFS::Trip, GTFS::StopTime,
GTFS::Calendar, GTFS::CalendarDate, GTFS::Shape, GTFS::FareAttribute,
GTFS::FareRule, GTFS::Frequency, GTFS::Transfer]
GTFS::FareRule, GTFS::Frequency, GTFS::Transfer, GTFS::FeedInfo]

REQUIRED_SOURCE_FILES = ENTITIES.select(&:required_file?).map(&:filename)
OPTIONAL_SOURCE_FILES = ENTITIES.reject(&:required_file?).map(&:filename)
Expand Down
14 changes: 14 additions & 0 deletions spec/gtfs/feed_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe GTFS::FeedInfo do
describe 'FeedInfo.parse_feed_infos' do
let(:header_line) {"feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version\n"}
let(:invalid_header_line) {"feed_publisher_name,feed_publisher_url,feed_start_date,feed_end_date,feed_version\n"}
let(:valid_line) {"Torrance Transit,http://Transit.TorranceCA.gov,en,20141102,20151003,1413\n"}
let(:invalid_line) {"Torrance Transit,http://Transit.TorranceCA.gov\n"}

subject {GTFS::FeedInfo.parse_feed_infos(source_text, opts)}

include_examples 'models'
end
end

0 comments on commit da1872e

Please sign in to comment.