Class: Alf::Predicate::ToRubyCode
- Inherits:
-
Sexpr::Processor
- Object
- Sexpr::Processor
- Alf::Predicate::ToRubyCode
- Defined in:
- lib/alf/predicate/processors/to_ruby_code.rb
Instance Method Summary collapse
- #on_contradiction(sexpr) ⇒ Object
- #on_dyadic(sexpr) ⇒ Object (also: #on_eq, #on_neq, #on_lt, #on_lte, #on_gt, #on_gte)
- #on_identifier(sexpr) ⇒ Object
- #on_in(sexpr) ⇒ Object
- #on_literal(sexpr) ⇒ Object
- #on_nadic_bool(sexpr) ⇒ Object (also: #on_and, #on_or)
- #on_not(sexpr) ⇒ Object
- #on_qualified_identifier(sexpr) ⇒ Object
- #on_tautology(sexpr) ⇒ Object
Instance Method Details
#on_contradiction(sexpr) ⇒ Object
9 10 11 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 9 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
37 38 39 40 41 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 37 def on_dyadic(sexpr) sexpr.sexpr_body.map{|term| apply(term, sexpr) }.join(" #{sexpr.operator_symbol} ") end |
#on_identifier(sexpr) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 17 def on_identifier(sexpr) if s = [:scope] "#{s}.#{sexpr.last.to_s}" else sexpr.last.to_s end end |
#on_in(sexpr) ⇒ Object
49 50 51 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 49 def on_in(sexpr) "#{Support.to_ruby_literal(sexpr.values)}.include?(#{apply(sexpr.identifier)})" end |
#on_literal(sexpr) ⇒ Object
53 54 55 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 53 def on_literal(sexpr) Support.to_ruby_literal(sexpr.last) end |
#on_nadic_bool(sexpr) ⇒ Object Also known as: on_and, on_or
29 30 31 32 33 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 29 def on_nadic_bool(sexpr) sexpr.sexpr_body.map{|term| apply(term, sexpr) }.join(" #{sexpr.operator_symbol} ") end |
#on_not(sexpr) ⇒ Object
25 26 27 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 25 def on_not(sexpr) "#{sexpr.operator_symbol}" << apply(sexpr.last, sexpr) end |
#on_qualified_identifier(sexpr) ⇒ Object
13 14 15 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 13 def on_qualified_identifier(sexpr) "#{sexpr.qualifier}.#{sexpr.name}" end |
#on_tautology(sexpr) ⇒ Object
5 6 7 |
# File 'lib/alf/predicate/processors/to_ruby_code.rb', line 5 def on_tautology(sexpr) "true" end |