Class: GtfsReader::Config::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/gtfs_reader/config/source.rb

Overview

A single source of GTFS data

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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.

Parameters:

  • title (String) (defaults to: nil)

    if given, will be used as the title of this source

Returns:

  • (String)

    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.

Parameters:

  • url (String) (defaults to: nil)

    if given, will be used as the URL for this source

Returns:

  • (String)

    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