class ConcatOperator
Public Class Methods
find_constants(problems)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 17 def self.find_constants(problems) problems.examples.inject([]) do |total, x| result = x.response.gsub( Regexp.new('^'+x.arguments.first),'') total << result unless result == x.response total end.uniq end
new(indexes)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 5 def initialize(indexes) @indexes = indexes @constant = 'bar' end
uses_block?()
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 29 def self.uses_block? false end
uses_constants?()
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 25 def self.uses_constants? true end
viable?(arguments, response)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 10 def self.viable?(arguments, response) return false unless arguments.all? { |x| x.kind_of?(String) } return false unless response.kind_of?(String) # TODO - Only accpets one argument true end
Public Instance Methods
branch?()
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 33 def branch? false end
build(operators, scope)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 49 def build(operators, scope) to_sexp(scope) end
successful?(problem)
click to toggle source
Operator for “x.concat(”bar“)”
# File lib/cauldron/operator/concat_operator.rb, line 38 def successful?(problem) if (problem[:arguments].first + @constant) == problem[:response] return true end return false end
to_ruby(scope, operators)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 45 def to_ruby(scope, operators) Sorcerer.source self.to_sexp(scope, operators) end
to_sexp(scope, operators)
click to toggle source
# File lib/cauldron/operator/concat_operator.rb, line 53 def to_sexp(scope, operators) first_variable = 'var'+@indexes[0].to_s [:program, [:stmts_add, [:stmts_new], [:method_add_arg, [:call, [:vcall, [:@ident, first_variable ]], :".", [:@ident, "concat"]], [:arg_paren, [:args_add_block, [:args_add, [:args_new], [:string_literal, [:string_add, [:string_content], [:@tstring_content, @constant]]]], false]]]]] end