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.



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

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

Parameters:

  • t (String) (defaults to: nil)

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

Returns:

  • (String)

    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.

Parameters:

  • u (String) (defaults to: nil)

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

Returns:

  • (String)

    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