10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/colorant/parser.rb', line 10
def parse(raw_data)
collection = []
raw_data.split("\n").map(&:strip).each do |line|
line.match /^(\d+):.*rgb\((.*)%,(.*)%,(.*)%\)$/
freq = $1.to_i
red, green, blue = [$2,$3,$4].map do |color|
color.to_f / 100.to_f
end
collection << { :freq => freq,
:red => percent_to_number(red),
:green => percent_to_number(green),
:blue => percent_to_number(blue) }
end
total = collection.map{|element| element[:freq]}.inject(:+)
collection.each{|element| element[:freq] = number_to_percent(element[:freq], total)}
collection
end
|