Class: Inquirex::Rules::Base
- Inherits:
-
Object
- Object
- Inquirex::Rules::Base
- Defined in:
- lib/inquirex/rules/base.rb
Overview
Abstract base for rule AST nodes. Subclasses implement #evaluate and #to_s for use in transitions and visibility conditions. Rules are immutable and serialize to/from JSON for cross-platform evaluation.
Class Method Summary collapse
-
.from_h(hash) ⇒ Rules::Base
Deserializes a rule from a plain Hash (e.g. parsed from JSON).
Instance Method Summary collapse
-
#evaluate(_answers) ⇒ Boolean
Evaluates the rule against the current answer context.
-
#to_h ⇒ Hash
Serializes the rule to a plain Hash for JSON serialization.
-
#to_s ⇒ String
Human-readable representation (e.g. for graph labels).
Class Method Details
.from_h(hash) ⇒ Rules::Base
Deserializes a rule from a plain Hash (e.g. parsed from JSON).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inquirex/rules/base.rb', line 36 def self.from_h(hash) op = hash["op"] || hash[:op] case op.to_s when "contains" then Contains.from_h(hash) when "equals" then Equals.from_h(hash) when "greater_than" then GreaterThan.from_h(hash) when "less_than" then LessThan.from_h(hash) when "not_empty" then NotEmpty.from_h(hash) when "all" then All.from_h(hash) when "any" then Any.from_h(hash) else raise Inquirex::Errors::SerializationError, "Unknown rule operator: #{op.inspect}" end end |
Instance Method Details
#evaluate(_answers) ⇒ Boolean
Evaluates the rule against the current answer context.
13 14 15 |
# File 'lib/inquirex/rules/base.rb', line 13 def evaluate(_answers) raise NotImplementedError, "#{self.class}#evaluate must be implemented" end |
#to_h ⇒ Hash
Serializes the rule to a plain Hash for JSON serialization.
20 21 22 |
# File 'lib/inquirex/rules/base.rb', line 20 def to_h raise NotImplementedError, "#{self.class}#to_h must be implemented" end |
#to_s ⇒ String
Human-readable representation (e.g. for graph labels).
27 28 29 |
# File 'lib/inquirex/rules/base.rb', line 27 def to_s raise NotImplementedError, "#{self.class}#to_s must be implemented" end |