Class: Datafile::ZipDataset
- Inherits:
-
Object
- Object
- Datafile::ZipDataset
- Includes:
- LogUtils::Logging
- Defined in:
- lib/datafile/workers/zip/dataset.rb
Overview
use (rename to) ZipDatasetWorker/Helper/Wrapper/Fetcher/Downloader - why, why not ???
Instance Method Summary collapse
- #download ⇒ Object
- #dump ⇒ Object
-
#initialize(dataset) ⇒ ZipDataset
constructor
A new instance of ZipDataset.
- #local_zip_name ⇒ Object
-
#local_zip_path ⇒ Object
local zip path.
- #local_zip_root ⇒ Object
- #read ⇒ Object
-
#remote_zip_url ⇒ Object
remote zip url.
Constructor Details
#initialize(dataset) ⇒ ZipDataset
Returns a new instance of ZipDataset.
10 11 12 |
# File 'lib/datafile/workers/zip/dataset.rb', line 10 def initialize( dataset ) @dataset = dataset end |
Instance Method Details
#download ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/datafile/workers/zip/dataset.rb', line 33 def download logger.info( "download dataset '#{@dataset.name}'" ) logger.info( " from '#{remote_zip_url}'" ) logger.info( " to '#{local_zip_path}'..." ) download_blob( remote_zip_url, local_zip_path ) end |
#dump ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/datafile/workers/zip/dataset.rb', line 42 def dump ## for debuggin dump dataset (also check if zip exits) puts "dataset '#{@dataset.name}' opts=#{@dataset.opts.to_json}" ## use opts.inspect instead of to_json - why? why not? puts " local '#{local_zip_name}' (#{local_zip_path})" if File.exist?( local_zip_path ) puts " size: #{File.size(local_zip_path)} bytes" else puts " (file not found)" end puts " remote '#{remote_zip_url}'" end |
#local_zip_name ⇒ Object
18 19 20 21 22 |
# File 'lib/datafile/workers/zip/dataset.rb', line 18 def local_zip_name ### note: replace / in name w/ --I-- ## e.g. flatten the filename, that is, do NOT include any folders @dataset.name.gsub('/', '--I--') # note: will NOT include/return .zip extension end |
#local_zip_path ⇒ Object
local zip path
28 29 30 |
# File 'lib/datafile/workers/zip/dataset.rb', line 28 def local_zip_path # local zip path "#{local_zip_root}/#{local_zip_name}.zip" end |
#local_zip_root ⇒ Object
24 25 26 |
# File 'lib/datafile/workers/zip/dataset.rb', line 24 def local_zip_root "./tmp" end |
#read ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/datafile/workers/zip/dataset.rb', line 54 def read if @dataset.is_a?( FootballDataset ) logger.info( "read football dataset (zip) '#{@dataset.name}', '#{@dataset.setup}'" ) pack = SportDb::ZipPackage.new( local_zip_path ) pack.read( season: @dataset.setup ) ## note: pass on (optional) setup arg as season (filter) arg for now else logger.info( "TODO/FIX: read dataset (zip) '#{@dataset.name}', '#{@dataset.setup}'; sorry" ) end end |
#remote_zip_url ⇒ Object
remote zip url
14 15 16 |
# File 'lib/datafile/workers/zip/dataset.rb', line 14 def remote_zip_url # remote zip url "https://github.com/#{@dataset.name}/archive/master.zip" end |