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(t = nil) ⇒ String
The title of this source.
-
#url(u = nil) ⇒ String
The URL this source’s ZIP file.
Constructor Details
#initialize(name) ⇒ Source
Returns a new instance of Source.
14 15 16 17 18 |
# File 'lib/gtfs_reader/config/source.rb', line 14 def initialize(name) @name = name @feed_definition = Config::Defaults::FEED_DEFINITION @feed_handler = FeedHandler.new {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/gtfs_reader/config/source.rb', line 12 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
36 37 38 39 40 41 |
# File 'lib/gtfs_reader/config/source.rb', line 36 def before(&block) if block_given? @before = block end @before end |
#feed_definition(&block) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/gtfs_reader/config/source.rb', line 43 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
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gtfs_reader/config/source.rb', line 53 def handlers(*args, &block) if block_given? opts = Hash === args.last ? 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(t = nil) ⇒ String
Returns the title of this source.
22 23 24 25 |
# File 'lib/gtfs_reader/config/source.rb', line 22 def title(t=nil) @title = t if t.present? @title end |
#url(u = nil) ⇒ String
Returns the URL this source’s ZIP file.
29 30 31 32 |
# File 'lib/gtfs_reader/config/source.rb', line 29 def url(u=nil) @url = u if u.present? @url end |