Class: Thwomp::ColorCounter

Inherits:
Struct
  • Object
show all
Defined in:
lib/thwomp/color_counter.rb

Overview

Flattens all colors in given image file and calculates the diversity in used colors We can asume that if the image contains more than 2 colors, we have an interesting image

Constant Summary collapse

FLATTEN_FACTOR =
4.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#image_filenameObject

Returns the value of attribute image_filename

Returns:

  • (Object)

    the current value of image_filename



6
7
8
# File 'lib/thwomp/color_counter.rb', line 6

def image_filename
  @image_filename
end

Instance Method Details

#diversityObject

returns the number of different colors



11
12
13
# File 'lib/thwomp/color_counter.rb', line 11

def diversity
  color_count.keys
end

#empty?Boolean

tests if the image is empty

Returns:

  • (Boolean)


16
17
18
# File 'lib/thwomp/color_counter.rb', line 16

def empty?
  diversity.size < 2
end

#present?Boolean

tests if the image contains an photo

Returns:

  • (Boolean)


21
22
23
# File 'lib/thwomp/color_counter.rb', line 21

def present?
  !empty?
end

#valid_png?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/thwomp/color_counter.rb', line 25

def valid_png?
  !!png
end