Class: ASEPalette::Color

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

Direct Known Subclasses

CMYK, GRAY, LAB, RGB

Defined Under Namespace

Classes: CMYK, GRAY, LAB, RGB

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

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



7
8
9
# File 'lib/ase-palette/color.rb', line 7

def name
  @name
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#modelObject

Get color model



11
12
13
# File 'lib/ase-palette/color.rb', line 11

def model
  self.class.to_s.split('::').last.downcase.to_sym
end

#to_hObject

Convert color to hash, necessary for binary representation



25
26
27
28
29
30
31
32
# File 'lib/ase-palette/color.rb', line 25

def to_h
  {
    name: @name,
    model: model,
    data: data,
    type: @type,
  }
end

#to_sObject

Convert color to string



16
17
18
19
20
21
# File 'lib/ase-palette/color.rb', line 16

def to_s
  "#{@name}, " \
  "#{model.upcase}: " \
  "#{data.values.join("/")}, " \
  ":#{@type}"
end