Class: SpotFeel::Dmn::UnaryTests
- Inherits:
-
LiteralExpression
- Object
- LiteralExpression
- SpotFeel::Dmn::UnaryTests
- Defined in:
- lib/spot_feel/dmn/unary_tests.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from LiteralExpression
#as_json, builtin_functions, #evaluate, #functions, #initialize, #named_functions, #named_variables
Constructor Details
This class inherits a constructor from SpotFeel::Dmn::LiteralExpression
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 6 def id @id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 6 def text @text end |
Class Method Details
.from_json(json) ⇒ Object
8 9 10 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 8 def self.from_json(json) UnaryTests.new(id: json[:id], text: json[:text]) end |
Instance Method Details
#test(input, variables = {}) ⇒ Object
21 22 23 24 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 21 def test(input, variables = {}) return true if text.nil? || text == '-' tree.eval(functions.merge(variables)).call(input) end |
#tree ⇒ Object
12 13 14 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 12 def tree @tree ||= Parser.parse_test(text) end |
#valid? ⇒ Boolean
16 17 18 19 |
# File 'lib/spot_feel/dmn/unary_tests.rb', line 16 def valid? return true if text.nil? || text == '-' tree.present? end |