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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datafile/datafile.rb', line 44

def initialize( opts={} )
  @opts     = opts
  @datasets = []
  @scripts  = []   ## calculation scripts (calc blocks)

  ## (target)name - return nil if noname (set/defined/assigned)
  @name  = opts[:name] || nil
  ## deps (dependencies) - note: always returns an array (empty array if no deps)
  @deps  = opts[:deps] || []     

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

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



62
63
64
# File 'lib/datafile/datafile.rb', line 62

def datasets
  @datasets
end

#depsObject (readonly)

dep(endencies)



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

def deps
  @deps
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#scriptsObject (readonly)

calc(ulation) scripts (calc blocks)



63
64
65
# File 'lib/datafile/datafile.rb', line 63

def scripts
  @scripts
end

#workerObject

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



67
68
69
# File 'lib/datafile/datafile.rb', line 67

def worker
  @worker
end

Class Method Details

.load(code) ⇒ Object

another convenience method - use like Datafile.load()



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

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 ;-)
  builder.datafile   
end

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

convenience method - use like Datafile.load_file()



26
27
28
29
# File 'lib/datafile/datafile.rb', line 26

def self.load_file( path='./Datafile' )
  code = File.read_utf8( path )
  self.load( code )
end

Instance Method Details

#calcObject



90
91
92
93
# File 'lib/datafile/datafile.rb', line 90

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

#downloadObject



79
80
81
82
83
# File 'lib/datafile/datafile.rb', line 79

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



95
96
97
98
99
# File 'lib/datafile/datafile.rb', line 95

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



85
86
87
88
# File 'lib/datafile/datafile.rb', line 85

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

#runObject



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

def run
  logger.info( "[datafile] begin - run" )
  download     # step 1 - download zips for datasets
  read         # step 2 - read in datasets from zips
  calc         # step 3 - run calc(ulations) scripts
  logger.info( "[datafile] end - run" )
end