Class: Lutaml::Xml::Decisions::DecisionRule Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/decisions/decision_rule.rb

Overview

This class is abstract.

Subclass and implement #applies? and #decide

Abstract base class for namespace decision rules

Each rule encapsulates ONE decision criterion. Rules are evaluated in priority order. First rule that applies determines the decision.

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Integer

Compare rules by priority (for sorting)

Parameters:

Returns:

  • (Integer)

    -1, 0, or 1



48
49
50
# File 'lib/lutaml/xml/decisions/decision_rule.rb', line 48

def <=>(other)
  priority <=> other.priority
end

#applies?(context) ⇒ Boolean

Check if this rule applies to the given context

Parameters:

Returns:

  • (Boolean)

    true if this rule should be applied

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/lutaml/xml/decisions/decision_rule.rb', line 18

def applies?(context)
  raise NotImplementedError, "#{self.class} must implement #applies?"
end

#decide(context) ⇒ Decision

Make the decision for this rule

Parameters:

Returns:

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/lutaml/xml/decisions/decision_rule.rb', line 26

def decide(context)
  raise NotImplementedError, "#{self.class} must implement #decide"
end

#nameString

Human-readable name of this rule

Returns:

  • (String)


40
41
42
# File 'lib/lutaml/xml/decisions/decision_rule.rb', line 40

def name
  self.class.name.split("::").last
end

#priorityInteger

Get the priority of this rule (lower = higher priority)

Returns:

  • (Integer)

    Priority (0-10)

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/lutaml/xml/decisions/decision_rule.rb', line 33

def priority
  raise NotImplementedError, "#{self.class} must implement #priority"
end