Permalink
Browse files

calendar parsing

  • Loading branch information...
nerdEd committed Feb 16, 2012
1 parent af80785 commit cfbf2ba38f8b15c9cdf53838499cb09662bb7b33
Showing with 28 additions and 0 deletions.
  1. +12 −0 lib/gtfs/calendar.rb
  2. +2 −0 lib/gtfs/model.rb
  3. +14 −0 spec/gtfs/calendar_spec.rb
View
@@ -0,0 +1,12 @@
+module GTFS
+ class Calendar
+ include GTFS::Model
+
+ required_attrs :service_id, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date
+ attr_accessor *attrs
+
+ def self.parse_calendars(data)
+ return parse_models(data)
+ end
+ end
+end
View
@@ -6,6 +6,8 @@ def self.included(base)
base.extend ClassMethods
const_set('PREFIX', '')
+ const_set('OPTIONAL_ATTRS', [])
+ const_set('REQUIRED_ATTRS', [])
def valid?
!self.class::REQUIRED_ATTRS.any?{|f| self.send(f.to_sym).nil?}
View
@@ -0,0 +1,14 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe GTFS::Calendar do
+ describe 'Calendar.parse_calendars' do
+ let(:header_line) {"service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date\n"}
+ let(:invalid_header_line) {"service_id,,tuesday,,thursday,friday,,sunday,start_date,end_date\n"}
+ let(:valid_line) {"1,1,1,1,1,1,0,0,20110828,20120204\n"}
+ let(:invalid_line) {"1,,1,,1,,0,,,20120204\n"}
+
+ subject {GTFS::Calendar.parse_calendars(source_text)}
+
+ include_examples 'models'
+ end
+end

0 comments on commit cfbf2ba

Please sign in to comment.