class IfRelationship

Public Class Methods

match?(problems) click to toggle source
# File lib/cauldron/if_relationship.rb, line 21
def self.match?(problems)
  true
end
new(problems) click to toggle source

TODO Need to change to IfSolution probably

# File lib/cauldron/if_relationship.rb, line 5
def initialize(problems)
  @problems = problems
end

Public Instance Methods

to_ruby(variables) click to toggle source
# File lib/cauldron/if_relationship.rb, line 9
def to_ruby(variables)

  # Add the arguments
  result = ''
  @problems.each_with_index do |x,i|
    result += '  if '+variables[0].to_s+' == '+quote(x.arguments[0])+"\n"
    result += '    return '+quote(x.response)+"\n"
    result += '  end'+"\n"
  end    
  result
end

Protected Instance Methods

quote(value) click to toggle source

TODO Not Dry - method used in Pot

# File lib/cauldron/if_relationship.rb, line 28
def quote(value)
  if value.kind_of?(String)
    return "'#{value}'"
  end
  value.to_s
end