Skip to content

Commit

Permalink
Add "entities_count" method
Browse files Browse the repository at this point in the history
  • Loading branch information
zog committed Jun 25, 2019
1 parent 3d9e501 commit 9c025d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/gtfs/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/gtfs/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GTFS
VERSION = '0.3.0'
VERSION = '0.3.1'
end
10 changes: 10 additions & 0 deletions spec/gtfs/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9c025d3

Please sign in to comment.