Class: ColorProximity

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

Constant Summary collapse

VERSION =
'0.2.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(threshold, collection) ⇒ ColorProximity

Returns a new instance of ColorProximity.



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

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

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



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

def collection
  @collection
end

#thresholdObject

Returns the value of attribute threshold.



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

def threshold
  @threshold
end

Instance Method Details

#past_threshold?(color) ⇒ Boolean

Returns:

  • (Boolean)


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

def past_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

#thresholds(color) ⇒ Object



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

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