Class: ASEPalette::Group
- Inherits:
-
Object
- Object
- ASEPalette::Group
- Defined in:
- lib/ase-palette/group.rb
Instance Attribute Summary collapse
-
#colors ⇒ Object
readonly
Name and colors cannot changed once a group is created in order to protect the integrity of unique names in a palette.
-
#name ⇒ Object
readonly
Name and colors cannot changed once a group is created in order to protect the integrity of unique names in a palette.
Instance Method Summary collapse
-
#initialize(name) ⇒ Group
constructor
Initialize group.
- #remove_color_with_name(name) ⇒ Object
-
#to_h ⇒ Object
Convert group to hash, necessary for binary representation.
-
#to_s ⇒ Object
Convert group to string.
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
#colors ⇒ Object (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 |
#name ⇒ Object (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_h ⇒ Object
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_s ⇒ Object
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 |