Class: GtfsReader::SourceUpdater
- Inherits:
-
Object
- Object
- GtfsReader::SourceUpdater
- Defined in:
- lib/gtfs_reader/source_updater.rb
Instance Method Summary collapse
- #before_callbacks ⇒ Object
-
#check_columns ⇒ Object
Check that every file has its required columns.
- #check_files ⇒ Object
- #check_optional_files ⇒ Object
- #check_required_files ⇒ Object
-
#finish ⇒ Object
Close any streams still open.
-
#initialize(name, source) ⇒ SourceUpdater
constructor
A new instance of SourceUpdater.
- #process_files ⇒ Object
-
#read ⇒ Object
Download the data from the remote server.
Constructor Details
#initialize(name, source) ⇒ SourceUpdater
Returns a new instance of SourceUpdater.
13 14 15 |
# File 'lib/gtfs_reader/source_updater.rb', line 13 def initialize(name, source) @name, @source = name, source end |
Instance Method Details
#before_callbacks ⇒ Object
17 18 19 |
# File 'lib/gtfs_reader/source_updater.rb', line 17 def before_callbacks @source.before.call fetch_remote_etag if @source.before end |
#check_columns ⇒ Object
Check that every file has its required columns
59 60 61 62 63 64 65 |
# File 'lib/gtfs_reader/source_updater.rb', line 59 def check_columns @found_files.each do |file| @zip.file.open(file.filename) do |data| FileReader.new data, file, validate: true end end end |
#check_files ⇒ Object
39 40 41 42 43 |
# File 'lib/gtfs_reader/source_updater.rb', line 39 def check_files @found_files = [] check_required_files check_optional_files end |
#check_optional_files ⇒ Object
52 53 54 55 56 |
# File 'lib/gtfs_reader/source_updater.rb', line 52 def check_optional_files Log.info { 'optional files'.cyan } files = @source.feed_definition.optional_files check_missing_files files, :cyan, :light_yellow end |
#check_required_files ⇒ Object
45 46 47 48 49 50 |
# File 'lib/gtfs_reader/source_updater.rb', line 45 def check_required_files Log.info { 'required files'.magenta } files = @source.feed_definition.required_files missing = check_missing_files files, :green, :red raise RequiredFilenamesMissing, missing unless missing.empty? end |
#finish ⇒ Object
Close any streams still open
34 35 36 37 |
# File 'lib/gtfs_reader/source_updater.rb', line 34 def finish @zip.close if @zip @file.delete if @file end |
#process_files ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/gtfs_reader/source_updater.rb', line 67 def process_files @found_files.each do |file| if @source.handlers.handler? file.name process_from_temp_file file else Log.warn { "Skipping #{file.filename.yellow} (no handler)" } end end end |
#read ⇒ Object
Download the data from the remote server
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gtfs_reader/source_updater.rb', line 22 def read Log.debug { " Reading #{@source.url.green}" } @file = Tempfile.new 'gtfs' @file.binmode @file << open(@source.url).read @file.rewind #binding.pry @zip = Zip::File.open @file Log.debug { "Finished reading #{@source.url.green}" } end |