Class: See5::Rule
- Inherits:
-
Object
- Object
- See5::Rule
- Defined in:
- lib/see5/rule.rb
Instance Attribute Summary collapse
-
#classification ⇒ Object
readonly
Returns the value of attribute classification.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#rule_info ⇒ Object
readonly
Returns the value of attribute rule_info.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rule_info, conditions, class_info) ⇒ Rule
constructor
A new instance of Rule.
- #match?(data) ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rule_info, conditions, class_info) ⇒ Rule
Returns a new instance of Rule.
7 8 9 10 11 12 |
# File 'lib/see5/rule.rb', line 7 def initialize(rule_info, conditions, class_info) @rule_info = rule_info @conditions = conditions @classification = class_info[:classification] @confidence = class_info[:confidence] end |
Instance Attribute Details
#classification ⇒ Object (readonly)
Returns the value of attribute classification.
5 6 7 |
# File 'lib/see5/rule.rb', line 5 def classification @classification end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/see5/rule.rb', line 5 def conditions @conditions end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
5 6 7 |
# File 'lib/see5/rule.rb', line 5 def confidence @confidence end |
#rule_info ⇒ Object (readonly)
Returns the value of attribute rule_info.
5 6 7 |
# File 'lib/see5/rule.rb', line 5 def rule_info @rule_info end |
Class Method Details
.from_h(h) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/see5/rule.rb', line 27 def self.from_h(h) new(h[:rule_info], h[:conditions], { classification: h[:classification], confidence: h[:confidence] }) end |
Instance Method Details
#match?(data) ⇒ Boolean
14 15 16 17 18 |
# File 'lib/see5/rule.rb', line 14 def match?(data) conditions .map { |attr, val| data[attr] == val } .all? { |matched| matched == true } end |
#to_h ⇒ Object
20 21 22 23 24 25 |
# File 'lib/see5/rule.rb', line 20 def to_h { rule_info: rule_info, conditions: conditions, classification: classification, confidence: confidence } end |
#to_s ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/see5/rule.rb', line 34 def to_s [ "See5::Rule", "@classification=#{classification}", "@conditions=#{conditions}" ] .join(", ") .yield_self { |s| "#<#{s}>" } end |