Class: Lizard::Histogram

Inherits:
Object
  • Object
show all
Defined in:
lib/lizard/histogram.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Histogram

Returns a new instance of Histogram.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lizard/histogram.rb', line 5

def initialize(data)
  stdout, stderr, exit_code = Lizard.run_command("convert - -colors 16 -depth 8 -format %c histogram:info:-", data)
  if exit_code == 0
    stdout = stdout.split(/\n/)
    @colors = stdout.each_with_object(Array.new) do |line, colors|
      if line =~ /\A\s*(\d+)\:.*\#([A-F0-9]{6}).*\z/
        colors << Color.new($1.to_i, $2)
      end
    end.sort_by(&:frequency)
  else
    raise Error, "Could not get histogram"
  end
end

Instance Method Details

#colorsObject



19
20
21
# File 'lib/lizard/histogram.rb', line 19

def colors
  @colors ||= []
end