Class: Sablon::Statement::Condition
- Inherits:
-
Struct
- Object
- Struct
- Sablon::Statement::Condition
- Defined in:
- lib/sablon/operations.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#conditon_expr ⇒ Object
Returns the value of attribute conditon_expr.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
Instance Method Summary collapse
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
28 29 30 |
# File 'lib/sablon/operations.rb', line 28 def block @block end |
#conditon_expr ⇒ Object
Returns the value of attribute conditon_expr
28 29 30 |
# File 'lib/sablon/operations.rb', line 28 def conditon_expr @conditon_expr end |
#predicate ⇒ Object
Returns the value of attribute predicate
28 29 30 |
# File 'lib/sablon/operations.rb', line 28 def predicate @predicate end |
Instance Method Details
#evaluate(context) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/sablon/operations.rb', line 29 def evaluate(context) value = conditon_expr.evaluate(context) if truthy?(predicate ? value.public_send(predicate) : value) block.replace(block.process(context).reverse) else block.replace([]) end end |
#truthy?(value) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/sablon/operations.rb', line 38 def truthy?(value) case value when Array; !value.empty? else !!value end end |