diff --git a/lib/gtfs.rb b/lib/gtfs.rb index 2ed6c0d..9d42ec2 100644 --- a/lib/gtfs.rb +++ b/lib/gtfs.rb @@ -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' diff --git a/lib/gtfs/feed_info.rb b/lib/gtfs/feed_info.rb new file mode 100644 index 0000000..32298d8 --- /dev/null +++ b/lib/gtfs/feed_info.rb @@ -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 diff --git a/lib/gtfs/source.rb b/lib/gtfs/source.rb index 2e1a9d5..a2c7818 100644 --- a/lib/gtfs/source.rb +++ b/lib/gtfs/source.rb @@ -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) diff --git a/spec/gtfs/feed_info_spec.rb b/spec/gtfs/feed_info_spec.rb new file mode 100644 index 0000000..684fff6 --- /dev/null +++ b/spec/gtfs/feed_info_spec.rb @@ -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