class StringAsteriskOperator

Public Class Methods

find_constants(problems) click to toggle source
# 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) click to toggle source

end

# 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) click to toggle source
# 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
new(indexes) click to toggle source

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

# File lib/cauldron/operator/string_asterisk_operator.rb, line 25
def initialize(indexes)
  @indexes = indexes
  @constant = 2
  #@constant, @indexes = constant, indexes
end
uses_block?() click to toggle source
# File lib/cauldron/operator/string_asterisk_operator.rb, line 101
def self.uses_block?
  false
end
uses_constants?() click to toggle source
# File lib/cauldron/operator/string_asterisk_operator.rb, line 97
def self.uses_constants?
  true
end
viable?(arguments,output) click to toggle source
# 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

Public Instance Methods

branch?() click to toggle source
# File lib/cauldron/operator/string_asterisk_operator.rb, line 105
def branch?
  false
end
build(operators, scope) click to toggle source

TODO Get rid of the defined names

# File lib/cauldron/operator/string_asterisk_operator.rb, line 127
def build(operators, scope)
  to_sexp(operators, scope)
end
successful?(problem) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

def to_sexp(operators, scope)

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

end

# 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