Module: SpotFeel

Defined in:
lib/spot_feel.rb,
lib/spot_feel/dmn.rb,
lib/spot_feel/nodes.rb,
lib/spot_feel/parser.rb,
lib/spot_feel/version.rb,
lib/spot_feel/dmn/rule.rb,
lib/spot_feel/dmn/input.rb,
lib/spot_feel/dmn/output.rb,
lib/spot_feel/dmn/decision.rb,
lib/spot_feel/dmn/variable.rb,
lib/spot_feel/configuration.rb,
lib/spot_feel/dmn/definitions.rb,
lib/spot_feel/dmn/unary_tests.rb,
lib/spot_feel/dmn/decision_table.rb,
lib/spot_feel/dmn/literal_expression.rb,
lib/spot_feel/dmn/information_requirement.rb

Defined Under Namespace

Modules: Dmn Classes: Addition, BooleanLiteral, ClosedIntervalEnd, ClosedIntervalStart, Comparison, ComparisonOperator, Configuration, Conjunction, Context, ContextEntry, ContextEntryList, DateTimeLiteral, Disjunction, Division, EvaluationError, Exponentiation, FilterExpression, FormalParameter, FunctionDefinition, FunctionInvocation, IfExpression, InstanceOf, Interval, List, ListEntries, Multiplication, Name, Node, NullLiteral, NumericLiteral, OpenIntervalEnd, OpenIntervalStart, Parser, PositionalParameters, QualifiedName, QuantifiedExpression, SimpleExpressions, SimplePositiveUnaryTest, SimplePositiveUnaryTests, SimpleUnaryTests, StringLiteral, Subtraction, SyntaxError, UnaryOperator

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.configObject



56
57
58
# File 'lib/spot_feel.rb', line 56

def self.config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



60
61
62
# File 'lib/spot_feel.rb', line 60

def self.configure
  yield(config)
end

.decide(decision_id, definitions: nil, definitions_json: nil, definitions_xml: nil, variables: {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/spot_feel.rb', line 39

def self.decide(decision_id, definitions: nil, definitions_json: nil, definitions_xml: nil, variables: {})
  if definitions_xml.present?
    definitions = Dmn::Definitions.from_xml(definitions_xml)
  elsif definitions_json.present?
    definitions = Dmn::Definitions.from_json(definitions_json)
  end
  definitions.evaluate(decision_id, variables: variables)
end

.definitions_from_json(json) ⇒ Object



52
53
54
# File 'lib/spot_feel.rb', line 52

def self.definitions_from_json(json)
  Dmn::Definitions.from_json(json)
end

.definitions_from_xml(xml) ⇒ Object



48
49
50
# File 'lib/spot_feel.rb', line 48

def self.definitions_from_xml(xml)
  Dmn::Definitions.from_xml(xml)
end

.evaluate(expression_text, variables: {}) ⇒ Object

Raises:



27
28
29
30
31
# File 'lib/spot_feel.rb', line 27

def self.evaluate(expression_text, variables: {})
  literal_expression = Dmn::LiteralExpression.new(text: expression_text)
  raise SyntaxError, "Expression is not valid" unless literal_expression.valid?
  literal_expression.evaluate(variables)
end

.test(input, unary_tests_text, variables: {}) ⇒ Object

Raises:



33
34
35
36
37
# File 'lib/spot_feel.rb', line 33

def self.test(input, unary_tests_text, variables: {})
  unary_tests = Dmn::UnaryTests.new(text: unary_tests_text)
  raise SyntaxError, "Unary tests are not valid" unless unary_tests.valid?
  unary_tests.test(input, variables)
end