Class: Predicate::ToRubyCode

Inherits:
Sexpr::Processor
  • Object
show all
Defined in:
lib/predicate/processors/to_ruby_code.rb

Instance Method Summary collapse

Instance Method Details

#on_contradiction(sexpr) ⇒ Object



8
9
10
# File 'lib/predicate/processors/to_ruby_code.rb', line 8

def on_contradiction(sexpr)
  "false"
end

#on_dyadic(sexpr) ⇒ Object Also known as: on_eq, on_neq, on_lt, on_lte, on_gt, on_gte



36
37
38
39
40
# File 'lib/predicate/processors/to_ruby_code.rb', line 36

def on_dyadic(sexpr)
  sexpr.sexpr_body.map{|term|
    apply(term, sexpr)
  }.join(" #{sexpr.operator_symbol} ")
end

#on_identifier(sexpr) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/predicate/processors/to_ruby_code.rb', line 16

def on_identifier(sexpr)
  if s = options[:scope]
    "#{s}[:#{sexpr.last.to_s}]"
  else
    sexpr.last.to_s
  end
end

#on_in(sexpr) ⇒ Object



48
49
50
# File 'lib/predicate/processors/to_ruby_code.rb', line 48

def on_in(sexpr)
  "#{to_ruby_literal(sexpr.values)}.include?(#{apply(sexpr.identifier)})"
end

#on_literal(sexpr) ⇒ Object



52
53
54
# File 'lib/predicate/processors/to_ruby_code.rb', line 52

def on_literal(sexpr)
  to_ruby_literal(sexpr.last)
end

#on_nadic_bool(sexpr) ⇒ Object Also known as: on_and, on_or



28
29
30
31
32
# File 'lib/predicate/processors/to_ruby_code.rb', line 28

def on_nadic_bool(sexpr)
  sexpr.sexpr_body.map{|term|
    apply(term, sexpr)
  }.join(" #{sexpr.operator_symbol} ")
end

#on_not(sexpr) ⇒ Object



24
25
26
# File 'lib/predicate/processors/to_ruby_code.rb', line 24

def on_not(sexpr)
  "#{sexpr.operator_symbol}" << apply(sexpr.last, sexpr)
end

#on_qualified_identifier(sexpr) ⇒ Object



12
13
14
# File 'lib/predicate/processors/to_ruby_code.rb', line 12

def on_qualified_identifier(sexpr)
  "#{sexpr.qualifier}[:#{sexpr.name}]"
end

#on_tautology(sexpr) ⇒ Object



4
5
6
# File 'lib/predicate/processors/to_ruby_code.rb', line 4

def on_tautology(sexpr)
  "true"
end