gtfs 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +1 -10
- data/README.md +11 -1
- data/gtfs.gemspec +1 -1
- data/lib/gtfs/agency.rb +2 -2
- data/lib/gtfs/calendar.rb +2 -2
- data/lib/gtfs/calendar_date.rb +2 -2
- data/lib/gtfs/fare_attribute.rb +4 -4
- data/lib/gtfs/fare_rule.rb +2 -2
- data/lib/gtfs/frequency.rb +2 -2
- data/lib/gtfs/model.rb +28 -9
- data/lib/gtfs/route.rb +2 -2
- data/lib/gtfs/shape.rb +2 -2
- data/lib/gtfs/source.rb +16 -8
- data/lib/gtfs/stop.rb +3 -3
- data/lib/gtfs/stop_time.rb +2 -2
- data/lib/gtfs/transfer.rb +2 -2
- data/lib/gtfs/trip.rb +3 -3
- data/lib/gtfs/version.rb +1 -1
- data/spec/gtfs/agency_spec.rb +1 -1
- data/spec/gtfs/calendar_date_spec.rb +1 -1
- data/spec/gtfs/calendar_spec.rb +1 -1
- data/spec/gtfs/fare_attribute_spec.rb +14 -0
- data/spec/gtfs/fare_rule_spec.rb +13 -0
- data/spec/gtfs/frequency_spec.rb +14 -0
- data/spec/gtfs/route_spec.rb +1 -1
- data/spec/gtfs/shape_spec.rb +1 -1
- data/spec/gtfs/source_spec.rb +17 -11
- data/spec/gtfs/stop_spec.rb +1 -1
- data/spec/gtfs/stop_time_spec.rb +1 -1
- data/spec/gtfs/transfer_spec.rb +14 -0
- data/spec/gtfs/trip_spec.rb +1 -1
- data/spec/gtfs/url_source_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/model_shared_examples.rb +46 -22
- metadata +34 -44
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6e202d40048ac060db1447f2e6f94c9202af70a
|
4
|
+
data.tar.gz: fc6e8e422d530776b6678e0f076aedf49e0d93a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f5fbc2249a9a049c462a4d71f94b301c9531c61f06f39ad8061fa49a03533ef8babd0fda2be26d3b19f6996a6436024a0f0a227fd5db4a16c1f00abcf937465d
|
7
|
+
data.tar.gz: 2645241ee7194a697fec1bf6166ecd96ea10ec972651d914f5660ccb79fadd446348ba89b5ad1d80cb719ff3eb5cbeb54cafa1cbab5eb00b240ff2a7ebec574d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
columnize (0.3.6)
|
5
|
-
debugger (1.2.2)
|
6
|
-
columnize (>= 0.3.1)
|
7
|
-
debugger-linecache (~> 1.1.1)
|
8
|
-
debugger-ruby_core_source (~> 1.1.5)
|
9
|
-
debugger-linecache (1.1.2)
|
10
|
-
debugger-ruby_core_source (>= 1.1.1)
|
11
|
-
debugger-ruby_core_source (1.1.5)
|
12
4
|
diff-lcs (1.1.3)
|
13
5
|
fakeweb (1.3.0)
|
14
6
|
multi_json (1.0.4)
|
@@ -32,11 +24,10 @@ PLATFORMS
|
|
32
24
|
ruby
|
33
25
|
|
34
26
|
DEPENDENCIES
|
35
|
-
debugger
|
36
27
|
fakeweb
|
37
28
|
multi_json (= 1.0.4)
|
38
29
|
rake
|
39
30
|
rspec
|
40
|
-
rubyzip
|
31
|
+
rubyzip (< 1.0.0)
|
41
32
|
simplecov
|
42
33
|
vcr
|
data/README.md
CHANGED
@@ -6,8 +6,12 @@ A Ruby wrapper for the [General Transit Feed Specification](https://developers.g
|
|
6
6
|
|
7
7
|
Initialize a new GTFS source:
|
8
8
|
|
9
|
+
# Defaults to strict checking of required columns
|
9
10
|
source = GTFS::Source.build(<URI or Path to GTFS zip file>)
|
10
|
-
|
11
|
+
|
12
|
+
# Relax the column checks, useful for sources that don't conform to standard
|
13
|
+
source = GTFS::Source.build(<URI or Path to GTFS zip file>, {strict: false})
|
14
|
+
|
11
15
|
Accessing GTFS data from the source:
|
12
16
|
|
13
17
|
source.agencies
|
@@ -22,6 +26,12 @@ Accessing GTFS data from the source:
|
|
22
26
|
source.shapes
|
23
27
|
source.frequencies
|
24
28
|
source.transfers
|
29
|
+
|
30
|
+
Alternatively:
|
31
|
+
|
32
|
+
source.each_agency {|agency| puts agency}
|
33
|
+
...
|
34
|
+
source.each_transfer {|transfer| puts transfer}
|
25
35
|
|
26
36
|
### License
|
27
37
|
|
data/gtfs.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_dependency 'rake'
|
19
19
|
gem.add_dependency 'multi_json'
|
20
|
-
gem.add_dependency 'rubyzip'
|
20
|
+
gem.add_dependency 'rubyzip', '< 1.0.0'
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rspec', ['>= 2.0.0']
|
23
23
|
gem.add_development_dependency 'simplecov'
|
data/lib/gtfs/agency.rb
CHANGED
data/lib/gtfs/calendar.rb
CHANGED
data/lib/gtfs/calendar_date.rb
CHANGED
data/lib/gtfs/fare_attribute.rb
CHANGED
@@ -2,16 +2,16 @@ module GTFS
|
|
2
2
|
class FareAttribute
|
3
3
|
include GTFS::Model
|
4
4
|
|
5
|
-
has_required_attrs :fare_id, :price, :currency_type, :payment_method
|
6
|
-
has_optional_attrs :transfer_duration
|
5
|
+
has_required_attrs :fare_id, :price, :currency_type, :payment_method
|
6
|
+
has_optional_attrs :transfer_duration, :transfers
|
7
7
|
attr_accessor *attrs
|
8
8
|
|
9
9
|
collection_name :fare_attributes
|
10
10
|
required_file false
|
11
11
|
uses_filename 'fare_attributes.txt'
|
12
12
|
|
13
|
-
def self.parse_fare_attributes(data)
|
14
|
-
return parse_models(data)
|
13
|
+
def self.parse_fare_attributes(data, options={})
|
14
|
+
return parse_models(data, options)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/gtfs/fare_rule.rb
CHANGED
data/lib/gtfs/frequency.rb
CHANGED
data/lib/gtfs/model.rb
CHANGED
@@ -64,23 +64,42 @@ module GTFS
|
|
64
64
|
|
65
65
|
def collection_name(collection_name)
|
66
66
|
self.define_singleton_method(:name) {collection_name}
|
67
|
+
|
68
|
+
self.define_singleton_method(:singular_name) {
|
69
|
+
self.to_s.split('::').last.
|
70
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
71
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
72
|
+
tr("-", "_").downcase
|
73
|
+
}
|
67
74
|
end
|
68
|
-
|
69
|
-
def uses_filename(filename)
|
75
|
+
|
76
|
+
def uses_filename(filename)
|
70
77
|
self.define_singleton_method(:filename) {filename}
|
71
78
|
end
|
72
79
|
|
73
|
-
def
|
80
|
+
def each(filename)
|
81
|
+
CSV.foreach(filename, :headers => true) do |row|
|
82
|
+
yield parse_model(row.to_hash)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse_model(attr_hash, options={})
|
87
|
+
unprefixed_attr_hash = {}
|
88
|
+
|
89
|
+
attr_hash.each do |key, val|
|
90
|
+
unprefixed_attr_hash[key.gsub(/^#{prefix}/, '')] = val
|
91
|
+
end
|
92
|
+
|
93
|
+
model = self.new(unprefixed_attr_hash)
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_models(data, options={})
|
74
97
|
return [] if data.nil? || data.empty?
|
75
98
|
|
76
99
|
models = []
|
77
100
|
CSV.parse(data, :headers => true) do |row|
|
78
|
-
|
79
|
-
|
80
|
-
attr_hash[key.gsub(/^#{prefix}/, '')] = val
|
81
|
-
end
|
82
|
-
model = self.new(attr_hash)
|
83
|
-
models << model if model.valid?
|
101
|
+
model = parse_model(row.to_hash, options)
|
102
|
+
models << model if options[:strict] == false || model.valid?
|
84
103
|
end
|
85
104
|
models
|
86
105
|
end
|
data/lib/gtfs/route.rb
CHANGED
data/lib/gtfs/shape.rb
CHANGED
data/lib/gtfs/source.rb
CHANGED
@@ -5,7 +5,7 @@ require 'zip/zip'
|
|
5
5
|
module GTFS
|
6
6
|
class Source
|
7
7
|
|
8
|
-
ENTITIES = [GTFS::Agency, GTFS::Stop, GTFS::Route, GTFS::Trip, GTFS::StopTime,
|
8
|
+
ENTITIES = [GTFS::Agency, GTFS::Stop, GTFS::Route, GTFS::Trip, GTFS::StopTime,
|
9
9
|
GTFS::Calendar, GTFS::CalendarDate, GTFS::Shape, GTFS::FareAttribute,
|
10
10
|
GTFS::FareRule, GTFS::Frequency, GTFS::Transfer]
|
11
11
|
|
@@ -13,9 +13,11 @@ module GTFS
|
|
13
13
|
OPTIONAL_SOURCE_FILES = ENTITIES.reject(&:required_file?).map(&:filename)
|
14
14
|
SOURCE_FILES = ENTITIES.map(&:filename)
|
15
15
|
|
16
|
-
|
16
|
+
DEFAULT_OPTIONS = {strict: true}
|
17
17
|
|
18
|
-
|
18
|
+
attr_accessor :source, :archive, :options
|
19
|
+
|
20
|
+
def initialize(source, opts={})
|
19
21
|
raise 'Source cannot be nil' if source.nil?
|
20
22
|
|
21
23
|
@tmp_dir = Dir.mktmpdir
|
@@ -23,6 +25,8 @@ module GTFS
|
|
23
25
|
|
24
26
|
@source = source
|
25
27
|
load_archive(@source)
|
28
|
+
|
29
|
+
@options = DEFAULT_OPTIONS.merge(opts)
|
26
30
|
end
|
27
31
|
|
28
32
|
def self.finalize(directory)
|
@@ -41,11 +45,11 @@ module GTFS
|
|
41
45
|
raise 'Cannot directly instantiate base GTFS::Source'
|
42
46
|
end
|
43
47
|
|
44
|
-
def self.build(data_root)
|
48
|
+
def self.build(data_root, opts={})
|
45
49
|
if File.exists?(data_root)
|
46
|
-
LocalSource.new(data_root)
|
50
|
+
src = LocalSource.new(data_root, opts)
|
47
51
|
else
|
48
|
-
URLSource.new(data_root)
|
52
|
+
src = URLSource.new(data_root, opts)
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
@@ -61,9 +65,13 @@ module GTFS
|
|
61
65
|
ENTITIES.each do |entity|
|
62
66
|
define_method entity.name.to_sym do
|
63
67
|
parse_file entity.filename do |f|
|
64
|
-
entity.send("parse_#{entity.name}".to_sym, f.read)
|
68
|
+
entity.send("parse_#{entity.name}".to_sym, f.read, options)
|
65
69
|
end
|
66
70
|
end
|
71
|
+
|
72
|
+
define_method "each_#{entity.singular_name}".to_sym do |&block|
|
73
|
+
entity.each(File.join(@tmp_dir, entity.filename)) { |model| block.call model }
|
74
|
+
end
|
67
75
|
end
|
68
76
|
|
69
77
|
def files
|
@@ -72,7 +80,7 @@ module GTFS
|
|
72
80
|
|
73
81
|
def parse_file(filename)
|
74
82
|
raise_if_missing_source filename
|
75
|
-
open File.join(@tmp_dir, '/', filename) do |f|
|
83
|
+
open File.join(@tmp_dir, '/', filename), 'r:bom|utf-8' do |f|
|
76
84
|
files[filename] ||= yield f
|
77
85
|
end
|
78
86
|
end
|
data/lib/gtfs/stop.rb
CHANGED
@@ -3,7 +3,7 @@ module GTFS
|
|
3
3
|
include GTFS::Model
|
4
4
|
|
5
5
|
has_required_attrs :id, :name, :lat, :lon
|
6
|
-
has_optional_attrs :code, :desc, :zone_id, :url, :location_type, :parent_station, :timezone
|
6
|
+
has_optional_attrs :code, :desc, :zone_id, :url, :location_type, :parent_station, :timezone, :wheelchair_boarding
|
7
7
|
column_prefix :stop_
|
8
8
|
attr_accessor *attrs
|
9
9
|
|
@@ -14,8 +14,8 @@ module GTFS
|
|
14
14
|
LOCATION_TYPE_STOP = 0
|
15
15
|
LOCATION_TYPE_STATION = 1
|
16
16
|
|
17
|
-
def self.parse_stops(data)
|
18
|
-
return parse_models(data)
|
17
|
+
def self.parse_stops(data, options={})
|
18
|
+
return parse_models(data, options)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/gtfs/stop_time.rb
CHANGED
data/lib/gtfs/transfer.rb
CHANGED
data/lib/gtfs/trip.rb
CHANGED
@@ -3,7 +3,7 @@ module GTFS
|
|
3
3
|
include GTFS::Model
|
4
4
|
|
5
5
|
has_required_attrs :route_id, :service_id, :id
|
6
|
-
has_optional_attrs :headsign, :short_name, :direction_id, :block_id, :shape_id
|
6
|
+
has_optional_attrs :headsign, :short_name, :direction_id, :block_id, :shape_id, :wheelchair_accessible
|
7
7
|
attr_accessor *attrs
|
8
8
|
|
9
9
|
column_prefix :trip_
|
@@ -12,8 +12,8 @@ module GTFS
|
|
12
12
|
required_file true
|
13
13
|
uses_filename 'trips.txt'
|
14
14
|
|
15
|
-
def self.parse_trips(data)
|
16
|
-
return parse_models(data)
|
15
|
+
def self.parse_trips(data, options={})
|
16
|
+
return parse_models(data, options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/gtfs/version.rb
CHANGED
data/spec/gtfs/agency_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Agency do
|
|
7
7
|
let(:valid_line) {"1,Maryland Transit Administration,http://www.mta.maryland.gov,America/New_York,en,410-539-5000\n"}
|
8
8
|
let(:invalid_line) {"1,,http://www.mta.maryland.gov,America/New_York,en,410-539-5000\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Agency.parse_agencies(source_text)}
|
10
|
+
subject {GTFS::Agency.parse_agencies(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
@@ -7,7 +7,7 @@ describe GTFS::CalendarDate do
|
|
7
7
|
let(:valid_line) {"3,20110905,1\n"}
|
8
8
|
let(:invalid_line) {"3,,1\n"}
|
9
9
|
|
10
|
-
subject {GTFS::CalendarDate.parse_calendar_dates(source_text)}
|
10
|
+
subject {GTFS::CalendarDate.parse_calendar_dates(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
data/spec/gtfs/calendar_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Calendar do
|
|
7
7
|
let(:valid_line) {"1,1,1,1,1,1,0,0,20110828,20120204\n"}
|
8
8
|
let(:invalid_line) {"1,,1,,1,,0,,,20120204\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Calendar.parse_calendars(source_text)}
|
10
|
+
subject {GTFS::Calendar.parse_calendars(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe GTFS::FareAttribute do
|
4
|
+
describe '.parse_fare_attributes' do
|
5
|
+
let(:header_line) {"fare_id,price,currency_type,payment_method,transfers,transfer_duration\n"}
|
6
|
+
let(:invalid_header_line) {",,currency_type,,,transfer_duration\n"}
|
7
|
+
let(:valid_line) {"1,1.23,USD,0, ,5000\n"}
|
8
|
+
let(:invalid_line) {"1,,,0, ,5000\n"}
|
9
|
+
|
10
|
+
subject {GTFS::FareAttribute.parse_fare_attributes(source_text, opts)}
|
11
|
+
|
12
|
+
include_examples 'models'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe GTFS::FareRule do
|
4
|
+
describe '.parse_fare_rules' do
|
5
|
+
let(:header_line) {"fare_id,route_id,origin_id,destination_id,contains_id\n"}
|
6
|
+
let(:invalid_header_line) {",route_id,origin_id,destination_id,contains_id\n"}
|
7
|
+
let(:valid_line) {"1,2,TWS,,\n"}
|
8
|
+
let(:invalid_line) {",2,TWS,,\n"}
|
9
|
+
subject {GTFS::FareRule.parse_fare_rules(source_text, opts)}
|
10
|
+
|
11
|
+
include_examples 'models'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe GTFS::Frequency do
|
4
|
+
describe '#parse_frequncies' do
|
5
|
+
let(:header_line) {"trip_id,start_time,end_time,headway_secs\n"}
|
6
|
+
let(:invalid_header_line) {",,end_time,headway_secs\n"}
|
7
|
+
let(:valid_line) {"AWE1,05:30:00,06:30:00,300\n"}
|
8
|
+
let(:invalid_line) {",,06:30:00,300\n"}
|
9
|
+
|
10
|
+
subject {GTFS::Frequency.parse_frequencies(source_text, opts)}
|
11
|
+
|
12
|
+
include_examples 'models'
|
13
|
+
end
|
14
|
+
end
|
data/spec/gtfs/route_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Route do
|
|
7
7
|
let(:valid_line) {"4679,1,001,SINAI - FORT McHENRY,,3,,0000FF,FFFFFF\n"}
|
8
8
|
let(:invalid_line) {",1,,,,3,,,FFFFFF\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Route.parse_routes(source_text)}
|
10
|
+
subject {GTFS::Route.parse_routes(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
data/spec/gtfs/shape_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Shape do
|
|
7
7
|
let(:valid_line) {"59135,39.354286,-76.662453,19,0.8136\n"}
|
8
8
|
let(:invalid_line) {",39.354286,,,0.8136\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Shape.parse_shapes(source_text)}
|
10
|
+
subject {GTFS::Shape.parse_shapes(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
data/spec/gtfs/source_spec.rb
CHANGED
@@ -10,29 +10,36 @@ describe GTFS::Source do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#build' do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
GTFS::URLSource.stub(:new).and_return('URLSource')
|
17
|
-
GTFS::LocalSource.stub(:new).and_return('LocalSource')
|
18
|
-
end
|
13
|
+
let(:opts) {{}}
|
14
|
+
let(:data_source) {valid_local_source}
|
15
|
+
subject {GTFS::Source.build(data_source, opts)}
|
19
16
|
|
20
17
|
context 'with a url as a data root' do
|
21
|
-
|
18
|
+
use_vcr_cassette('valid_gtfs_uri')
|
19
|
+
let(:data_source) {'http://dl.dropbox.com/u/416235/work/valid_gtfs.zip'}
|
22
20
|
|
23
|
-
it {should
|
21
|
+
it {should be_instance_of GTFS::URLSource}
|
22
|
+
its(:options) {should == GTFS::Source::DEFAULT_OPTIONS}
|
24
23
|
end
|
25
24
|
|
26
25
|
context 'with a file path as a data root' do
|
27
26
|
let(:data_source) {valid_local_source}
|
28
27
|
|
29
|
-
it {should
|
28
|
+
it {should be_instance_of GTFS::LocalSource}
|
29
|
+
its(:options) {should == GTFS::Source::DEFAULT_OPTIONS}
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'with a file object as a data root' do
|
33
33
|
let(:data_source) {File.open(valid_local_source)}
|
34
34
|
|
35
|
-
it {should
|
35
|
+
it {should be_instance_of GTFS::LocalSource}
|
36
|
+
its(:options) {should == GTFS::Source::DEFAULT_OPTIONS}
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with options to disable strict checks' do
|
40
|
+
let(:opts) {{strict: false}}
|
41
|
+
|
42
|
+
its(:options) {should == {strict: false}}
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
@@ -51,7 +58,6 @@ describe GTFS::Source do
|
|
51
58
|
it {should_not be_empty}
|
52
59
|
its(:first) {should be_an_instance_of(GTFS::Agency)}
|
53
60
|
end
|
54
|
-
|
55
61
|
end
|
56
62
|
|
57
63
|
describe '#stops' do
|
data/spec/gtfs/stop_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Stop do
|
|
7
7
|
let(:valid_line) {"3,C093,LANIER & SINAI HOSPITAL,39.351145,-76.663113,,,,\n"}
|
8
8
|
let(:invalid_line) {"3,,,,-76.663113,,,,\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Stop.parse_stops(source_text)}
|
10
|
+
subject {GTFS::Stop.parse_stops(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
data/spec/gtfs/stop_time_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::StopTime do
|
|
7
7
|
let(:valid_line) {"982385,4:34:00,4:34:00,277,1,,0,0,\n"}
|
8
8
|
let(:invalid_line) {",,4:34:00,,1,,,0,\n"}
|
9
9
|
|
10
|
-
subject {GTFS::StopTime.parse_stop_times(source_text)}
|
10
|
+
subject {GTFS::StopTime.parse_stop_times(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe GTFS::Transfer do
|
4
|
+
describe '#parse_transfers' do
|
5
|
+
let(:header_line) {"from_stop_id,to_stop_id,transfer_type,min_transfer_time\n"}
|
6
|
+
let(:invalid_header_line) {",toxxtop_id,transfer_type,min_transfer_time\n"}
|
7
|
+
let(:valid_line) {"S6,S7,2,300\n"}
|
8
|
+
let(:invalid_line) {",S7,2,300\n"}
|
9
|
+
|
10
|
+
subject {GTFS::Transfer.parse_transfers(source_text, opts)}
|
11
|
+
|
12
|
+
include_examples 'models'
|
13
|
+
end
|
14
|
+
end
|
data/spec/gtfs/trip_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GTFS::Trip do
|
|
7
7
|
let(:valid_line) {"4679,1,982394,1 FT McHENRY,0,189021,59135\n"}
|
8
8
|
let(:invalid_line) {",1,,1 FT McHENRY,,189021,\n"}
|
9
9
|
|
10
|
-
subject {GTFS::Trip.parse_trips(source_text)}
|
10
|
+
subject {GTFS::Trip.parse_trips(source_text, opts)}
|
11
11
|
|
12
12
|
include_examples 'models'
|
13
13
|
end
|
@@ -5,7 +5,7 @@ describe GTFS::URLSource do
|
|
5
5
|
let(:source_path) {'http://dl.dropbox.com/u/416235/work/valid_gtfs.zip'}
|
6
6
|
it 'should create a new source successfully' do
|
7
7
|
VCR.use_cassette('valid_gtfs_uri') do
|
8
|
-
lambda {GTFS::URLSource.new(source_path)}.should_not raise_error(GTFS::InvalidSourceException)
|
8
|
+
lambda {GTFS::URLSource.new(source_path, {})}.should_not raise_error(GTFS::InvalidSourceException)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -14,7 +14,7 @@ describe GTFS::URLSource do
|
|
14
14
|
let(:source_path) {'http://www.edschmalzle.com/gtfs.zip'}
|
15
15
|
it 'should raise an exception' do
|
16
16
|
VCR.use_cassette('invalid_gtfs_uri') do
|
17
|
-
lambda {GTFS::URLSource.new(source_path)}.should raise_error(GTFS::InvalidSourceException)
|
17
|
+
lambda {GTFS::URLSource.new(source_path, {})}.should raise_error(GTFS::InvalidSourceException)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,31 +1,55 @@
|
|
1
1
|
shared_examples 'models' do |collection_class|
|
2
|
-
context 'with a nil source' do
|
3
|
-
let(:source_text) {nil}
|
4
|
-
it {should == []}
|
5
|
-
end
|
6
2
|
|
7
|
-
context 'with
|
8
|
-
let(:
|
9
|
-
it {should == []}
|
10
|
-
end
|
3
|
+
context 'with default options' do
|
4
|
+
let(:opts) {{}}
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
context 'with a nil source' do
|
7
|
+
let(:source_text) {nil}
|
8
|
+
it {should == []}
|
9
|
+
end
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
context 'with an empty source' do
|
12
|
+
let(:source_text) {''}
|
13
|
+
it {should == []}
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a source w/ only headers' do
|
17
|
+
let(:source_text) {header_line}
|
18
|
+
it {should == []}
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
context 'with a valid row of data' do
|
22
|
+
let(:source_text) {header_line + valid_line}
|
23
|
+
its(:size) {should == 1}
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with multiple valid rows of data' do
|
27
|
+
let(:source_text) {header_line + valid_line + valid_line}
|
28
|
+
its(:size) {should == 2}
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with 1 invalid and 1 valid row of data' do
|
32
|
+
let(:source_text) {header_line + valid_line + invalid_line}
|
33
|
+
its(:size) {should == 1}
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with an invalid line' do
|
37
|
+
let(:source_text) {header_line + invalid_line}
|
38
|
+
its(:size) {should == 0}
|
39
|
+
end
|
25
40
|
end
|
26
41
|
|
27
|
-
context 'with
|
28
|
-
let(:
|
29
|
-
|
42
|
+
context 'with options set to turn off strict checking' do
|
43
|
+
let(:opts) {{strict: false}}
|
44
|
+
|
45
|
+
context 'with an invalid line' do
|
46
|
+
let(:source_text) {header_line + invalid_line}
|
47
|
+
its(:size) {should == 1}
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with 1 invalid and 1 valid row of data' do
|
51
|
+
let(:source_text) {header_line + valid_line + invalid_line}
|
52
|
+
its(:size) {should == 2}
|
53
|
+
end
|
30
54
|
end
|
31
55
|
end
|
metadata
CHANGED
@@ -1,145 +1,128 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- nerdEd
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: multi_json
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rubyzip
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - <
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 1.0.0
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - <
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
54
|
+
version: 1.0.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 2.0.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 2.0.0
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: simplecov
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: ruby-debug19
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: vcr
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: fakeweb
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - '>='
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '0'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - '>='
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '0'
|
142
|
-
description:
|
125
|
+
description: "gtfs reads GTFS data from a google-compliant Zip bundle \n and
|
143
126
|
returns an object representing the CSV data inside"
|
144
127
|
email:
|
145
128
|
- ed@nerded.net
|
@@ -180,39 +163,42 @@ files:
|
|
180
163
|
- spec/gtfs/agency_spec.rb
|
181
164
|
- spec/gtfs/calendar_date_spec.rb
|
182
165
|
- spec/gtfs/calendar_spec.rb
|
166
|
+
- spec/gtfs/fare_attribute_spec.rb
|
167
|
+
- spec/gtfs/fare_rule_spec.rb
|
168
|
+
- spec/gtfs/frequency_spec.rb
|
183
169
|
- spec/gtfs/local_source_spec.rb
|
184
170
|
- spec/gtfs/route_spec.rb
|
185
171
|
- spec/gtfs/shape_spec.rb
|
186
172
|
- spec/gtfs/source_spec.rb
|
187
173
|
- spec/gtfs/stop_spec.rb
|
188
174
|
- spec/gtfs/stop_time_spec.rb
|
175
|
+
- spec/gtfs/transfer_spec.rb
|
189
176
|
- spec/gtfs/trip_spec.rb
|
190
177
|
- spec/gtfs/url_source_spec.rb
|
191
178
|
- spec/spec_helper.rb
|
192
179
|
- spec/support/model_shared_examples.rb
|
193
180
|
homepage: https://github.com/nerdEd/gtfs
|
194
181
|
licenses: []
|
182
|
+
metadata: {}
|
195
183
|
post_install_message:
|
196
184
|
rdoc_options: []
|
197
185
|
require_paths:
|
198
186
|
- lib
|
199
187
|
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
-
none: false
|
201
188
|
requirements:
|
202
|
-
- -
|
189
|
+
- - '>='
|
203
190
|
- !ruby/object:Gem::Version
|
204
191
|
version: '0'
|
205
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
-
none: false
|
207
193
|
requirements:
|
208
|
-
- -
|
194
|
+
- - '>='
|
209
195
|
- !ruby/object:Gem::Version
|
210
196
|
version: '0'
|
211
197
|
requirements: []
|
212
198
|
rubyforge_project:
|
213
|
-
rubygems_version: 1.
|
199
|
+
rubygems_version: 2.1.10
|
214
200
|
signing_key:
|
215
|
-
specification_version:
|
201
|
+
specification_version: 4
|
216
202
|
summary: Load and read GTFS data from zip bundles
|
217
203
|
test_files:
|
218
204
|
- spec/fixtures/cassettes/invalid_gtfs_uri.yml
|
@@ -222,12 +208,16 @@ test_files:
|
|
222
208
|
- spec/gtfs/agency_spec.rb
|
223
209
|
- spec/gtfs/calendar_date_spec.rb
|
224
210
|
- spec/gtfs/calendar_spec.rb
|
211
|
+
- spec/gtfs/fare_attribute_spec.rb
|
212
|
+
- spec/gtfs/fare_rule_spec.rb
|
213
|
+
- spec/gtfs/frequency_spec.rb
|
225
214
|
- spec/gtfs/local_source_spec.rb
|
226
215
|
- spec/gtfs/route_spec.rb
|
227
216
|
- spec/gtfs/shape_spec.rb
|
228
217
|
- spec/gtfs/source_spec.rb
|
229
218
|
- spec/gtfs/stop_spec.rb
|
230
219
|
- spec/gtfs/stop_time_spec.rb
|
220
|
+
- spec/gtfs/transfer_spec.rb
|
231
221
|
- spec/gtfs/trip_spec.rb
|
232
222
|
- spec/gtfs/url_source_spec.rb
|
233
223
|
- spec/spec_helper.rb
|