Module: GtfsReader

Defined in:
lib/gtfs_reader/config/defaults/gtfs_feed_definition.rb,
lib/gtfs_reader.rb,
lib/gtfs_reader/log.rb,
lib/gtfs_reader/core.rb,
lib/gtfs_reader/version.rb,
lib/gtfs_reader/file_row.rb,
lib/gtfs_reader/exceptions.rb,
lib/gtfs_reader/file_reader.rb,
lib/gtfs_reader/feed_handler.rb,
lib/gtfs_reader/config/column.rb,
lib/gtfs_reader/config/source.rb,
lib/gtfs_reader/configuration.rb,
lib/gtfs_reader/config/sources.rb,
lib/gtfs_reader/source_updater.rb,
lib/gtfs_reader/bulk_feed_handler.rb,
lib/gtfs_reader/config/feed_definition.rb,
lib/gtfs_reader/config/file_definition.rb

Overview

This default config file creates a [FeedDefinition] that matches the one specified by Google. You can use this definition in most cases. A custom definition will only be required if you need to parse a feed that differs in some critical way (Remember that these feeds are not always created by technically-proficient people). See developers.google.com/transit/gtfs/reference

Defined Under Namespace

Modules: Config, Log, Version Classes: BulkDsl, BulkFeedHandler, BulkFeedHandlerDsl, Configuration, FeedHandler, FeedHandlerDsl, FileReader, FileReaderError, FileRow, HandlerMissingError, ParserContext, RequiredColumnsMissing, RequiredFilenamesMissing, SkipSourceError, SourceUpdater, UnknownSourceError

Constant Summary collapse

CSV_OPTIONS =
{ headers: :first_row,
return_headers: true,
header_converters: :symbol }.freeze

Class Method Summary collapse

Class Method Details

.config(*args, &blk) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/gtfs_reader/core.rb', line 18

def config(*args, &blk)
  @cfg ||= create_config

  if block_given?
    @cfg.instance_exec(*args.unshift(@cfg), &blk)
  elsif args.any?
    raise ArgumentError, 'arguments given without a block'
  end
  @cfg
end

.create_configObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gtfs_reader/core.rb', line 66

def create_config
  Configuration.new.tap do |cfg|
    cfg.instance_exec do
      parameter(:verbose)
      parameter(:skip_parsing)
      parameter(:return_hashes)
      block_parameter(:sources, Config::Sources)
      block_parameter(:feed_definition, Config::FeedDefinition)
    end
  end
end

.update(name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/gtfs_reader/core.rb', line 33

def update(name)
  if config.verbose
    update_verbosely(name)
  else
    Log.quiet { update_verbosely(name) }
  end
end

.update_all!Object



29
30
31
# File 'lib/gtfs_reader/core.rb', line 29

def update_all!
  config.sources.each { |name, _| update(name) }
end

.update_verbosely(name) ⇒ Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gtfs_reader/core.rb', line 41

def update_verbosely(name)
  source = config.sources[name]
  raise UnknownSourceError, "No source named '#{name}'" if source.nil?

  updater = SourceUpdater.new(name, source)
  begin
    updater.instance_exec do
      Log.info { "Updating #{name.to_s.green}".underline }
      before_callbacks
      download_source
      check_files
      check_columns
      process_files
      Log.info { "Finished updating #{name.to_s.green}" }
    end
  rescue SkipSourceError => e
    Log.warn do
      msg = e.message ? ": #{e.message}" : ''
      "#{'Skipping'.red} #{source.name.to_s.yellow}" + msg
    end
  ensure
    updater.close
  end
end