Class: Lizard::Histogram
- Inherits:
-
Object
- Object
- Lizard::Histogram
- Defined in:
- lib/lizard/histogram.rb
Instance Method Summary collapse
- #colors ⇒ Object
-
#initialize(data) ⇒ Histogram
constructor
A new instance of Histogram.
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
#colors ⇒ Object
19 20 21 |
# File 'lib/lizard/histogram.rb', line 19 def colors @colors ||= [] end |