Skip to content

Commit

Permalink
calendar parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdEd committed Feb 16, 2012
1 parent af80785 commit cfbf2ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/gtfs/calendar.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/gtfs/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?}
Expand Down
14 changes: 14 additions & 0 deletions spec/gtfs/calendar_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::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.