diff --git a/lib/gtfs/source.rb b/lib/gtfs/source.rb index a2c7818..a66311c 100644 --- a/lib/gtfs/source.rb +++ b/lib/gtfs/source.rb @@ -72,6 +72,10 @@ def raise_if_missing_source(filename) define_method "each_#{entity.singular_name}".to_sym do |&block| entity.each(File.join(@tmp_dir, entity.filename)) { |model| block.call model } end + + define_method "#{entity.name}_count".to_sym do |&block| + count = File.foreach(File.join(@tmp_dir, entity.filename)).inject(-1) {|c, _| c+1} + end end def files diff --git a/lib/gtfs/version.rb b/lib/gtfs/version.rb index 697769d..90aff31 100644 --- a/lib/gtfs/version.rb +++ b/lib/gtfs/version.rb @@ -1,3 +1,3 @@ module GTFS - VERSION = '0.3.0' + VERSION = '0.3.1' end diff --git a/spec/gtfs/source_spec.rb b/spec/gtfs/source_spec.rb index 95a2992..7cab38c 100644 --- a/spec/gtfs/source_spec.rb +++ b/spec/gtfs/source_spec.rb @@ -59,6 +59,16 @@ end end + describe '#agencies_count' do + subject {source.agencies_count} + + context 'when the source has agencies' do + let(:source) {GTFS::Source.build(valid_local_source)} + + it {should eq 1} + end + end + describe '#stops' do end