Class: Cauldron::DynamicOperator

Inherits:
Object
  • Object
show all
Includes:
Operator
Defined in:
lib/cauldron/dynamic_operator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operator

included

Constructor Details

#initialize(information, sexp_methods) ⇒ DynamicOperator

Returns a new instance of DynamicOperator.



10
11
12
13
14
# File 'lib/cauldron/dynamic_operator.rb', line 10

def initialize(information, sexp_methods)
  @information, @sexp_methods = information, sexp_methods
  @failed_uses = []
  @closed = false
end

Instance Attribute Details

#failed_usesObject

Returns the value of attribute failed_uses.



8
9
10
# File 'lib/cauldron/dynamic_operator.rb', line 8

def failed_uses
  @failed_uses
end

#indexesObject

Returns the value of attribute indexes.



7
8
9
# File 'lib/cauldron/dynamic_operator.rb', line 7

def indexes
  @indexes
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/cauldron/dynamic_operator.rb', line 25

def close
  @closed = true
end

#context_realizable?(context) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cauldron/dynamic_operator.rb', line 36

def context_realizable?(context)
  
  vars = context.keys.select {|x| x.match(/var\d/) }
  var_names = vars.collect(&:to_s)

  a = %Q{
  def function(var0)
    #{Sorcerer.source(to_sexp(Cauldron::Scope.new(var_names), []), indent: true)}
  end
  }       

  o = Object.new
  o.instance_eval(a)

  begin
    o.function(vars.collect {|x| context[x] })  
  rescue NoMethodError => e
    return false
  rescue StandardError => e
    puts e
  end
  return true
  
end

#extend_actualized_composite(x, container, examples, point) ⇒ Object



29
30
31
32
33
34
# File 'lib/cauldron/dynamic_operator.rb', line 29

def extend_actualized_composite(x, container, examples, point)
  cloned_container = container.clone_solution
  cloned_container.add_statement_at(x, point)
  cloned_container
  Cauldron::ActualizedComposite.new(cloned_container, examples)
end

#rip(composite, examples) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/cauldron/dynamic_operator.rb', line 79

def rip(composite,examples)
  Ripper::SexpBuilder.new(
    %Q{
    def function(var0)
      #{composite.to_ruby(examples.scope)}
    end
  }).parse      
end

#rip2Object



71
72
73
74
75
76
77
# File 'lib/cauldron/dynamic_operator.rb', line 71

def rip2
  %Q{
  def function(var0)
    #{Sorcerer.source(to_sexp(Cauldron::Scope.new(['var0'])), indent: true)}
  end
  }
end

#uses_constants?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/cauldron/dynamic_operator.rb', line 16

def uses_constants?
  @information[:constants]
end

#write_to_file(filename) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/cauldron/dynamic_operator.rb', line 61

def write_to_file(filename)
  FileUtils.mkdir_p File.join('tmp')
  File.open( File.join('tmp',filename), 'w+') do |file|
    file << "class DynamicOperator"+"\n"
    file << Sorcerer.source(@sexp_methods, indent: true)
    file << "\n"
    file << "end"
  end
end