Class: ColorCat::Process
- Inherits:
-
Object
- Object
- ColorCat::Process
- Defined in:
- lib/color_cat/process.rb
Constant Summary collapse
- NUMBER_OF_COLORS =
6
Instance Attribute Summary collapse
-
#color_details ⇒ Object
readonly
Returns the value of attribute color_details.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
-
#quantized ⇒ Object
readonly
Returns the value of attribute quantized.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #color_category(my_rgb) ⇒ Object
- #color_info ⇒ Object
- #dominant_category ⇒ Object
- #dominant_name ⇒ Object
- #ignore_white_bg? ⇒ Boolean
-
#initialize(url, opts = {}) ⇒ Process
constructor
A new instance of Process.
- #intensity ⇒ Object
- #to_hex ⇒ Object
- #to_rgb ⇒ Object
Constructor Details
#initialize(url, opts = {}) ⇒ Process
Returns a new instance of Process.
9 10 11 12 13 |
# File 'lib/color_cat/process.rb', line 9 def initialize(url, opts={}) @url = url @opts = opts @color_details = [] end |
Instance Attribute Details
#color_details ⇒ Object (readonly)
Returns the value of attribute color_details.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def color_details @color_details end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def opts @opts end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def original @original end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def primary @primary end |
#quantized ⇒ Object (readonly)
Returns the value of attribute quantized.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def quantized @quantized end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/color_cat/process.rb', line 5 def url @url end |
Class Method Details
.call(url, opts = {}) ⇒ Object
25 26 27 |
# File 'lib/color_cat/process.rb', line 25 def self.call(url, opts={}) new(url, opts).call end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/color_cat/process.rb', line 15 def call begin process_image normal = sort_by_decreasing_frequency(quantized) get_pix(normal) rescue OpenURI::HTTPError, Magick::ImageMagickError # TODO logging end end |
#color_category(my_rgb) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/color_cat/process.rb', line 29 def color_category(my_rgb) tmp_dist = 255*3 tmp_name = "none" tmp_category_color = "none" Colors.each_pair do |name, rgb| category_color = rgb[0] rgb = rgb[1] total_dist = Math.sqrt((rgb[0] - my_rgb[0]) ** 2 + (rgb[1] - my_rgb[1]) ** 2 + (rgb[2] - my_rgb[2]) ** 2) if (total_dist < tmp_dist) tmp_name = name tmp_category_color = category_color tmp_dist = total_dist end end [tmp_category_color, tmp_name] end |
#color_info ⇒ Object
53 54 55 |
# File 'lib/color_cat/process.rb', line 53 def color_info color_details.compact end |
#dominant_category ⇒ Object
69 70 71 |
# File 'lib/color_cat/process.rb', line 69 def dominant_category color_info.first[:color_cat] end |
#dominant_name ⇒ Object
73 74 75 |
# File 'lib/color_cat/process.rb', line 73 def dominant_name color_info.first[:color_name] end |
#ignore_white_bg? ⇒ Boolean
49 50 51 |
# File 'lib/color_cat/process.rb', line 49 def ignore_white_bg? opts[:ignore_white_bg] end |
#intensity ⇒ Object
65 66 67 |
# File 'lib/color_cat/process.rb', line 65 def intensity color_info.first[:intensity] end |
#to_hex ⇒ Object
57 58 59 |
# File 'lib/color_cat/process.rb', line 57 def to_hex color_info.first[:hex] end |
#to_rgb ⇒ Object
61 62 63 |
# File 'lib/color_cat/process.rb', line 61 def to_rgb color_info.first[:rgb] end |