Class: Color

Inherits:
Object
  • Object
show all
Defined in:
lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r:, g:, b:, a:) ⇒ Color

Returns a new instance of Color.



14
15
16
17
18
19
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 14

def initialize(r:, g:, b:, a:)
  @r = r
  @g = g
  @b = b
  @a = a
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



4
5
6
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 4

def a
  @a
end

#bObject

Returns the value of attribute b.



4
5
6
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 4

def b
  @b
end

#gObject

Returns the value of attribute g.



4
5
6
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 4

def g
  @g
end

#rObject

Returns the value of attribute r.



4
5
6
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 4

def r
  @r
end

Class Method Details

.from_hash(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 21

def self.from_hash(hash)
  return nil if hash.nil?

  r = hash['r']
  g = hash['g']
  b = hash['b']
  a = hash['a']

  return Color.new(r: r, g: g, b: b, a: a) if !r.nil? && !g.nil? && !b.nil? && !a.nil?

  nil
end

Instance Method Details

#hexObject



6
7
8
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 6

def hex
  format('#%02x%02x%02x', *[r, g, b].map { |v| v.to_f * 255 }).upcase
end

#hex_with_alphaObject



10
11
12
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 10

def hex_with_alpha
  format('#%02x%02x%02x%02x', *[a, r, g, b].map { |v| v.to_f * 255 }).upcase
end

#to_hashObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb', line 34

def to_hash
  hash = {}
  hash['r'] = r
  hash['g'] = g
  hash['b'] = b
  hash['a'] = a
  hash['hex'] = hex
  hash['hex_with_alpha'] = hex_with_alpha
  hash
end