Class: ColorProximity

Inherits:
Object
  • Object
show all
Defined in:
lib/color-proximity.rb,
lib/color-proximity/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threshold, collection) ⇒ ColorProximity

Returns a new instance of ColorProximity.



7
8
9
10
# File 'lib/color-proximity.rb', line 7

def initialize(threshold, collection)
  @threshold = threshold
  @collection = collection
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



5
6
7
# File 'lib/color-proximity.rb', line 5

def collection
  @collection
end

#thresholdObject

Returns the value of attribute threshold.



5
6
7
# File 'lib/color-proximity.rb', line 5

def threshold
  @threshold
end

Instance Method Details

#thresholds(color) ⇒ Object



22
23
24
# File 'lib/color-proximity.rb', line 22

def thresholds(color)
  @collection.map { |collection_color| proximity_of(color, collection_color) }
end

#within_threshold?(color) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/color-proximity.rb', line 12

def within_threshold?(color)
  @collection.each_with_object([true]) do |collection_color, arr|
    proximity = proximity_of(color, collection_color)
    next unless @threshold > proximity
    arr[0] = false
    arr[1] = [] if arr[1].nil?
    arr[1] << collection_color
  end
end