Class: See5::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/see5/rule.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#classificationObject (readonly)

Returns the value of attribute classification.



5
6
7
# File 'lib/see5/rule.rb', line 5

def classification
  @classification
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/see5/rule.rb', line 5

def conditions
  @conditions
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



5
6
7
# File 'lib/see5/rule.rb', line 5

def confidence
  @confidence
end

#rule_infoObject (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

Returns:

  • (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_hObject



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_sObject



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