class HashKeyValueOperator

www.ruby-doc.org/core-2.1.1/Hash.html hsh → value

Public Class Methods

find_constants(problems) click to toggle source
# File lib/cauldron/operator/hash_key_value_operator.rb, line 22
def self.find_constants(problems)
  problems.collect {|x| x.arguments.first.keys }.flatten
end
new(indexes) click to toggle source

var0

# File lib/cauldron/operator/hash_key_value_operator.rb, line 7
def initialize(indexes)
  @indexes = indexes
  @constant = :foo
  #@constant, @indexes = constant, indexes
end
uses_constants?() click to toggle source
# File lib/cauldron/operator/hash_key_value_operator.rb, line 18
def self.uses_constants?
  true
end
viable?(arguments, response) click to toggle source
# File lib/cauldron/operator/hash_key_value_operator.rb, line 13
def self.viable?(arguments, response)
  return false unless arguments.all? { |x| x.kind_of?(Hash) }
  true
end

Public Instance Methods

sexp_index() click to toggle source
# File lib/cauldron/operator/hash_key_value_operator.rb, line 52
def sexp_index
  if @constant.kind_of?(Symbol)
    a = [
          :symbol_literal, 
          [:symbol, [:@ident, @constant]],
          [:string_add, [:@ident, @constant]]
        ]
    return a      
  elsif @constant.kind_of?(String)
    return [
              :string_literal, 
              [
                :string_add, 
                [:string_content], 
                [:@tstring_content, @constant ]
              ]
          ] 
  else
    raise StandardError.new('Unknown index')
  end
end
successful?(problem) click to toggle source
# File lib/cauldron/operator/hash_key_value_operator.rb, line 26
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/hash_key_value_operator.rb, line 33
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/hash_key_value_operator.rb, line 37
def to_sexp(scope, operators)
  [:aref,
    [:vcall, 
      [:@ident, scope[0]]
    ], 
    [:args_add_block, 
      [
        :args_add, 
        [:args_new], 
        sexp_index
      ]
    ]
  ]
end