Class: Gauguin::PaletteSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/gauguin/palette_serializer.rb

Class Method Summary collapse

Class Method Details

.dump(value) ⇒ Object



15
16
17
18
19
# File 'lib/gauguin/palette_serializer.rb', line 15

def self.dump(value)
  value = value.to_a.map { |color, group| [color.to_a, group] }
  value = Hash[value]
  YAML.dump(value)
end

.load(value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/gauguin/palette_serializer.rb', line 5

def self.load(value)
  return unless value

  value = YAML.load(value)
  value = value.to_a.map do |color_key, group|
    [Gauguin::Color.from_a(color_key), group]
  end
  value = Hash[value]
end