Class: Color
- Inherits:
-
Object
- Object
- Color
- Defined in:
- lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/color.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
- #hex ⇒ Object
- #hex_with_alpha ⇒ Object
-
#initialize(r:, g:, b:, a:) ⇒ Color
constructor
A new instance of Color.
- #to_hash ⇒ Object
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
#a ⇒ Object
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 |
#b ⇒ Object
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 |
#g ⇒ Object
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 |
#r ⇒ Object
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
#hex ⇒ Object
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_alpha ⇒ Object
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_hash ⇒ Object
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 |