Class: Datafile::ZipDataset

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(dataset) ⇒ ZipDataset

Returns a new instance of ZipDataset.



11
12
13
# File 'lib/datafile/workers/zip/dataset.rb', line 11

def initialize( dataset )
  @dataset = dataset
end

Instance Method Details

#downloadObject



34
35
36
37
38
39
40
# File 'lib/datafile/workers/zip/dataset.rb', line 34

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

#dumpObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/datafile/workers/zip/dataset.rb', line 43

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_nameObject



19
20
21
22
23
# File 'lib/datafile/workers/zip/dataset.rb', line 19

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_pathObject

local zip path



29
30
31
# File 'lib/datafile/workers/zip/dataset.rb', line 29

def local_zip_path  # local zip path
  "#{local_zip_root}/#{local_zip_name}.zip"
end

#local_zip_rootObject



25
26
27
# File 'lib/datafile/workers/zip/dataset.rb', line 25

def local_zip_root
  "./tmp"
end

#readObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/datafile/workers/zip/dataset.rb', line 55

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_urlObject

remote zip url



15
16
17
# File 'lib/datafile/workers/zip/dataset.rb', line 15

def remote_zip_url  # remote zip url
  "https://github.com/#{@dataset.name}/archive/master.zip"
end