Class: Fluent::InlineClassifierOutput::Classifier
- Inherits:
-
Object
- Object
- Fluent::InlineClassifierOutput::Classifier
- Defined in:
- lib/fluent/plugin/out_inline_classifier.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #classify(record) ⇒ Object
-
#initialize(key, store, rules) ⇒ Classifier
constructor
A new instance of Classifier.
- #run!(record) ⇒ Object
Constructor Details
#initialize(key, store, rules) ⇒ Classifier
Returns a new instance of Classifier.
9 10 11 12 13 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 9 def initialize(key, store, rules) @key = key @store = store @rules = rules end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 5 def key @key end |
#rules ⇒ Object
Returns the value of attribute rules.
7 8 9 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 7 def rules @rules end |
#store ⇒ Object
Returns the value of attribute store.
6 7 8 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 6 def store @store end |
Instance Method Details
#classify(record) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 15 def classify(record) return nil if not record.has_key?(@key) target = record[@key] @rules.each {|name, func| if func.call(target) return name end } return nil end |
#run!(record) ⇒ Object
27 28 29 30 31 |
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 27 def run!(record) if (name = classify(record)) != nil record[@store] = name end end |