Class: GtfsReader::SourceUpdater
- Inherits:
-
Object
- Object
- GtfsReader::SourceUpdater
- Defined in:
- lib/gtfs_reader/source_updater.rb
Overview
Downloads remote Feed files, checks that they are valid, and passes each file in the feed to the handlers in the given [Source].
Instance Method Summary collapse
-
#before_callbacks ⇒ Object
Call the “before” callback set on this source.
-
#check_columns ⇒ Object
Check that every file has its required columns.
-
#check_files ⇒ Object
Parse the filenames in the feed and check which required and optional files are present.
- #close ⇒ Object
-
#download_source ⇒ Object
Download the data from the remote server.
-
#initialize(name, source) ⇒ SourceUpdater
constructor
A new instance of SourceUpdater.
- #process_files ⇒ Object
Constructor Details
#initialize(name, source) ⇒ SourceUpdater
Returns a new instance of SourceUpdater.
16 17 18 19 20 |
# File 'lib/gtfs_reader/source_updater.rb', line 16 def initialize(name, source) @name = name @source = source @temp_files = {} end |
Instance Method Details
#before_callbacks ⇒ Object
Call the “before” callback set on this source
23 24 25 |
# File 'lib/gtfs_reader/source_updater.rb', line 23 def before_callbacks @source.before.call(fetch_data_set_identifier) if @source.before end |
#check_columns ⇒ Object
Check that every file has its required columns
64 65 66 67 68 69 70 |
# File 'lib/gtfs_reader/source_updater.rb', line 64 def check_columns @found_files.each do |file| @temp_files[file.filename].open do |data| FileReader.new(data, file, validate: true) end end end |
#check_files ⇒ Object
Parse the filenames in the feed and check which required and optional files are present.
53 54 55 56 57 58 59 60 61 |
# File 'lib/gtfs_reader/source_updater.rb', line 53 def check_files @found_files = [] check_required_files check_optional_files # Add feed files of zip to the list of files to be processed @source.feed_definition.files.each do |req| @found_files << req if filenames.include?(req.filename) end end |
#close ⇒ Object
45 46 47 |
# File 'lib/gtfs_reader/source_updater.rb', line 45 def close @temp_files.values.each(&:close) end |
#download_source ⇒ Object
Download the data from the remote server
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gtfs_reader/source_updater.rb', line 28 def download_source Log.debug { " Reading #{@source.url.green}" } zip = Tempfile.new('gtfs') zip.binmode zip << open(@source.url).read zip.rewind extract_to_tempfiles(zip) Log.debug { "Finished reading #{@source.url.green}" } rescue StandardException => e Log.error(e.) raise e ensure zip.try(:close) end |