Class: Contrek::Matchers::MatcherHsb

Inherits:
Matcher
  • Object
show all
Defined in:
lib/contrek/matchers/matcher_hsb.rb

Instance Attribute Summary

Attributes inherited from Matcher

#counters, #values

Instance Method Summary collapse

Methods inherited from Matcher

#initialize, #unmatch?

Constructor Details

This class inherits a constructor from Contrek::Matchers::Matcher

Instance Method Details

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/contrek/matchers/matcher_hsb.rb', line 4

def match?(value)
  if @values.index(value).nil?
    @values << value
    @counters[value] = {count: 1, match: 0}
  else
    @counters[value][:count] += 1
  end

  match = value[0].between?(@value_is[:h][:min], @value_is[:h][:max]) &&
    value[1].between?(@value_is[:s][:min], @value_is[:s][:max]) &&
    value[2].between?(@value_is[:b][:min], @value_is[:b][:max])

  if match
    @counters[value][:match] += 1
  end

  match
end