Class: Matcher::MatchHelper

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

Overview

MatchHelper class is responsible for matching records to quotas. Methods:

+get_quota+: Takes a list of keys and returns the quota that maximally matches
+matching_score+: Calculates the matching score between two hashes.

Instance Method Summary collapse

Constructor Details

#initialize(processed_quotas, default_quota) ⇒ MatchHelper

Returns a new instance of MatchHelper.



12
13
14
15
# File 'lib/fluent/plugin/matcher.rb', line 12

def initialize(processed_quotas,default_quota)
  @quotas = processed_quotas
  @default_quota = default_quota
end

Instance Method Details

#get_quota(record) ⇒ Object

Takes a list of keys and returns the quota that maximally matches If no quota matches, returns the default quota Params:

+record+: (Hash) A hash of keys and values to match against the quotas

Returns:

+quota+: (Quota Class)The quota that maximally matches the record


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/matcher.rb', line 23

def get_quota(record)

  max_score = 0
  quota_to_return = @default_quota
  if @quotas.nil?
    return @default_quota
  end
  @quotas.each do |quota|
    score = matching_score(quota.match_by, record)
    if score > max_score
      max_score = score
      quota_to_return = quota
    end
  end
  quota_to_return
end