Class: StringAsteriskOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/cauldron/operator/string_asterisk_operator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indexes) ⇒ StringAsteriskOperator

Although it should probably be

0

[ [‘a’] ]

1

[ [‘b’, ‘c’], [‘g’, ‘d’] ]

Or the order it was added might be more useful - e.g. last variable, second last variable or first variable

  • variable at depth(1) - stepUp(1).first



25
26
27
28
29
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 25

def initialize(indexes)
  @indexes = indexes
  @constant = 2
  #@constant, @indexes = constant, indexes
end

Class Method Details

.find_constants(problems) ⇒ Object



86
87
88
89
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 86

def self.find_constants(problems)
  return [] unless problems.all? { |x| x.response.kind_of?(String) }
  problems.collect {|x| x.response.scan(x.arguments.first).count }.reject {|x| x == 0}
end

.history_goals(context_history, target) ⇒ Object

end



81
82
83
84
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 81

def self.history_goals(context_history,target)
  variables = context_history.first.keys
  context_history.each {|x| x[variables.first] }.zip(target)
end

.instances(histories, composite, examples, insert_points) ⇒ Object



31
32
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/cauldron/operator/string_asterisk_operator.rb', line 31

def self.instances(histories, composite, examples, insert_points)

  # TEMP
  unless examples.class == ExampleSet
    raise StandardError.new('Examples should be an example')
  end

  # Print out each insertable statements
  scope = examples.scope

  # self.init([0]).to_ruby(scope)
  # - this will print out "var0.chop"

  # Get the variables available at each point
  results = []

  insert_points.each do |point|

    # Find the variables at a particular point
    # TODO Change to test
    contexts = histories.contexts_at(point)
    composites = context_instances(contexts)

    composites.each do |x|
      if contexts.all? do |context|
        x.context_realizable?(context)
      end
        results << extend_actualized_composite(x, composite, examples, point)
      end
    end

  end
  
  results
end

.uses_block?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 101

def self.uses_block?
  false
end

.uses_constants?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 97

def self.uses_constants?
  true
end

.viable?(arguments, output) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 91

def self.viable?(arguments,output)
  return false unless output.kind_of?(String)
  return false unless arguments.first.kind_of?(String)
  true
end

Instance Method Details

#branch?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 105

def branch?
  false
end

#build(operators, scope) ⇒ Object

TODO Get rid of the defined names



127
128
129
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 127

def build(operators, scope)
  to_sexp(operators, scope)
end

#successful?(problem) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 109

def successful?(problem)
  return true if problem[:arguments].first*@constant == problem[:response]    
  false
end

#to_ruby(scope, operators) ⇒ Object



114
115
116
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 114

def to_ruby(scope, operators)
  Sorcerer.source self.to_sexp([], scope)
end

#to_sexp(scope, children) ⇒ Object

def to_sexp(operators, scope)

[:binary, [:vcall, [:@ident, scope[@indexes[0]] ]], :*, [:@int, @constant]]

end



121
122
123
124
# File 'lib/cauldron/operator/string_asterisk_operator.rb', line 121

def to_sexp(scope, children)
  first_variable = 'var'+@indexes[0].to_s
  Ripper::SexpBuilder.new(%Q{#{first_variable} * #{@constant}}).parse
end