Class: Datafile::Datafile

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/datafile/datafile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Datafile

Returns a new instance of Datafile.



29
30
31
32
33
34
35
36
37
38
# File 'lib/datafile/datafile.rb', line 29

def initialize( opts={} )
  @opts     = opts
  @datasets = []

  @worker = if opts[:file]
              FileWorker.new( self )
            else   ## default to zip worker for now
              ZipWorker.new( self )
            end
end

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



40
41
42
# File 'lib/datafile/datafile.rb', line 40

def datasets
  @datasets
end

Class Method Details

.load(code) ⇒ Object

another convenience method - use like Datafile.load()



15
16
17
18
19
20
21
22
23
# File 'lib/datafile/datafile.rb', line 15

def self.load( code )
  builder = Builder.new
  builder.instance_eval( code )

  # Note: return datafile (of course, NOT the builder)
  #  if you want a builder use Datafile::Builder ;-)
  datafile = builder.datafile
  datafile
end

.load_file(path = './Datafile') ⇒ Object

convenience method - use like Datafile.load_file()



9
10
11
12
# File 'lib/datafile/datafile.rb', line 9

def self.load_file( path='./Datafile' )
  code = File.open( path, 'r:utf-8' ).read
  self.load( code )
end

Instance Method Details

#downloadObject



64
65
66
67
68
# File 'lib/datafile/datafile.rb', line 64

def download
  logger.info( "[datafile] dowload" )
  @worker.download
  ## check: use @worker.download( @datasets) - why, why not??  link worker w/ datafile - why, why not??
end

#dumpObject



75
76
77
78
79
# File 'lib/datafile/datafile.rb', line 75

def dump
  ## for debugging dump datasets (note: will/might also check if zip exits)
  logger.info( "[datafile] dump datasets (for debugging)" )
  @worker.dump
end

#readObject



70
71
72
73
# File 'lib/datafile/datafile.rb', line 70

def read
  logger.info( "[datafile] read" )
  @worker.read
end

#runObject



56
57
58
59
60
61
# File 'lib/datafile/datafile.rb', line 56

def run
  logger.info( "[datafile] begin - run" )
  download     # step 1 - download zips for datasets
  read         # step 2 - read in datasets from zips  - note: includes running inlines
  logger.info( "[datafile] end - run" )
end

#worker=(value) ⇒ Object

lets you change worker - find a better way - how, why, why not??



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

def worker=( value )  # lets you change worker - find a better way - how, why, why not??
  @worker =  if value.is_a?( Class )   ## let's you pass in FileWorker or ZipWorker etc.
               value.new( self )
             elsif value.to_sym == :file
               FileWorker.new( self )
             elsif value.to_sym == :zip
               ZipWorker.new( self )
             else
               value
             end
end