Class: Datafile::BuilderEx

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

Overview

check/todo: rename to BatchBuilder, MultiBuilder,etc - find better name - why, why not??

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilderEx

Returns a new instance of BuilderEx.



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

def initialize
  @datafiles = []
  @datafile = nil
end

Instance Attribute Details

#datafilesObject (readonly)

Returns the value of attribute datafiles.



30
31
32
# File 'lib/datafile/builder2.rb', line 30

def datafiles
  @datafiles
end

Class Method Details

.load(code) ⇒ Object



16
17
18
19
20
# File 'lib/datafile/builder2.rb', line 16

def self.load( code )
  builder = BuilderEx.new
  builder.instance_eval( code )
  builder
end

.load_file(path) ⇒ Object



11
12
13
14
# File 'lib/datafile/builder2.rb', line 11

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

Instance Method Details

#beer(name, opts = {}) ⇒ Object

“classic/standard” datasets



74
75
76
77
# File 'lib/datafile/builder2.rb', line 74

def beer( name, opts={} )
  logger.info( "[builder] add beer-dataset '#{name}'" )
  @datafile.datasets << BeerDataset.new( name, opts )
end

#calc(&block) ⇒ Object



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

def calc( &block )
  logger.info( "[builder] add script calc-block" )
  @datafile.scripts << Script.new( block )
end

#football(name, opts = {}) ⇒ Object



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

def football( name, opts={} )
  logger.info( "[builder] add football-dataset '#{name}'" )
  @datafile.datasets << FootballDataset.new( name, opts )
end

#task(arg) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/datafile/builder2.rb', line 33

def task( arg )

  logger.info( "[builder] add task '#{arg.inspect}' : #{arg.class.name}" )

  if arg.kind_of?( String ) || arg.kind_of?( Symbol )   # e.g. 'at' or :at
    name = arg.to_s
    ## note: always default to FileWorker for now
    ##  -- use file: true -- find better name e.g. worker/source: file - why? why not??
    @datafile = Datafile.new( name: name, deps: [], file: true )
    yield  ### execute block in context
     ## b = Builder.new
     ## block.call( b )  ## same as b.instance_eval( &block) ???
     ## b.instance_eval( code )
     ## b = Builder.load( &block )
  elsif arg.kind_of?( Hash )  ## Hash  e.g. :at_calc => :at etc.
    key   = arg.keys.first
    value = arg[key]   ## todo: check if single value? always turn into array

    name  = key.to_s   ## get first key (assume it's name)
    if value.kind_of?( Array )
      deps = value.map { |v| v.to_s }   ## convert to strings
    else  ## assume single string/symbol -- convert to array
      deps = [value.to_s]
    end
    @datafile = Datafile.new( name: name, deps: deps, file: true )  ## note: always default to FileWorker for now
    yield   ### execute block in context
    ## to be done
  else
    ## fix: report error: unknown type
  end

  @datafiles << @datafile
end

#world(name, opts = {}) ⇒ Object



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

def world( name, opts={} )
  logger.info( "[builder] add world-dataset '#{name}'" )
  @datafile.datasets << WorldDataset.new( name, opts )
end