Class: GtfsReader::Config::Source
- Inherits:
-
Object
- Object
- GtfsReader::Config::Source
- Defined in:
- lib/gtfs_reader/config/source.rb
Overview
A single source of GTFS data
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#before(&block) ⇒ Object
Define a block to call before the source is read.
- #feed_definition(&block) ⇒ Object
- #handlers(*args, &block) ⇒ Object
-
#initialize(name) ⇒ Source
constructor
A new instance of Source.
-
#title(title = nil) ⇒ String
The title of this source.
-
#url(url = nil) ⇒ String
The URL this source’s ZIP file.
Constructor Details
#initialize(name) ⇒ Source
Returns a new instance of Source.
15 16 17 18 19 20 21 |
# File 'lib/gtfs_reader/config/source.rb', line 15 def initialize(name) @name = name @feed_definition = Config::Defaults::FEED_DEFINITION @feed_handler = FeedHandler.new {} @url = nil @before = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/gtfs_reader/config/source.rb', line 13 def name @name end |
Instance Method Details
#before(&block) ⇒ Object
Define a block to call before the source is read. If this block returns false
, cancel processing the source
39 40 41 42 |
# File 'lib/gtfs_reader/config/source.rb', line 39 def before(&block) @before = block if block_given? @before end |
#feed_definition(&block) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/gtfs_reader/config/source.rb', line 44 def feed_definition(&block) if block_given? @feed_definition = FeedDefinition.new.tap do |feed| feed.instance_exec(feed, &block) end end @feed_definition end |
#handlers(*args, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gtfs_reader/config/source.rb', line 54 def handlers(*args, &block) if block_given? opts = args.last.try(:is_a?, Hash) ? args.pop : {} opts = opts.reverse_merge bulk: nil @feed_handler = if opts[:bulk] BulkFeedHandler.new(opts[:bulk], args, &block) else FeedHandler.new(args, &block) end end @feed_handler end |
#title(title = nil) ⇒ String
Returns the title of this source.
25 26 27 28 |
# File 'lib/gtfs_reader/config/source.rb', line 25 def title(title = nil) @title = title if title.present? @title end |
#url(url = nil) ⇒ String
Returns the URL this source’s ZIP file.
32 33 34 35 |
# File 'lib/gtfs_reader/config/source.rb', line 32 def url(url = nil) @url = url if url.present? @url end |