12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/colorant/reporter.rb', line 12
def report(data, options = {})
data.map! do |row|
color = ColorNamer.name_from_rgb(row[:red], row[:green], row[:blue])
if options[:extended]
name = color[1].match(color.last) ? color[1] : "#{color[1]} #{color.last}"
[name, row[:freq]]
else
[color.last, row[:freq]]
end
end
freqs = {}
data.each do |color|
if freqs[color[0]]
freqs[color[0]] += color[1]
else
freqs[color[0]] = color[1]
end
end
colors = freqs.to_a.sort{|a, b| b[1] <=> a[1]}
send(:"#{options[:reporter] || :ruby}_report", colors)
end
|