Class: Fluent::InlineClassifierOutput::Classifier

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/out_inline_classifier.rb

Direct Known Subclasses

RangeClassifier

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 5

def key
  @key
end

#rulesObject

Returns the value of attribute rules.



7
8
9
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 7

def rules
  @rules
end

#storeObject

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