Class: ASEPalette::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/ase-palette/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Group

Initialize group



8
9
10
11
# File 'lib/ase-palette/group.rb', line 8

def initialize(name)
  @name = name
  @colors = []
end

Instance Attribute Details

#colorsObject (readonly)

Name and colors cannot changed once a group is created in order to protect the integrity of unique names in a palette



5
6
7
# File 'lib/ase-palette/group.rb', line 5

def colors
  @colors
end

#nameObject (readonly)

Name and colors cannot changed once a group is created in order to protect the integrity of unique names in a palette



5
6
7
# File 'lib/ase-palette/group.rb', line 5

def name
  @name
end

Instance Method Details

#remove_color_with_name(name) ⇒ Object



35
36
37
# File 'lib/ase-palette/group.rb', line 35

def remove_color_with_name(name)
  @colors = @colors.select { |color| color.name != name }
end

#to_hObject

Convert group to hash, necessary for binary representation



28
29
30
31
32
33
# File 'lib/ase-palette/group.rb', line 28

def to_h
  {
    name: @name,
    colors: @colors.map(&:to_h),
  }
end

#to_sObject

Convert group to string



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ase-palette/group.rb', line 14

def to_s
  s = "- #{@name}:\n"
  if @colors.length > 0
    @colors.each do |color|
      s += "  #{color}\n"
    end
  else
    s += "  <empty>\n"
  end
  s
end