def initialize(palette)
@colors = []
@names = {}
@valid = false
@name = "(unnamed)"
palette.split($/).each do |line|
line.chomp!
line.gsub!(/\s*#.*\Z/, '')
next if line.empty?
if line =~ /\AGIMP Palette\Z/
@valid = true
next
end
info = /(\w+):\s(.*$)/.match(line)
if info
@name = info.captures[1] if info.captures[0] =~ /name/i
next
end
line.gsub!(/^\s+/, '')
data = line.split(/\s+/, 4)
name = data.pop.strip
data.map! { |el| el.to_i }
color = Color::RGB.new(*data)
@colors << color
@names[name] ||= []
@names[name] << color
end
end