Class: Component
- Inherits:
-
Object
- Object
- Component
- Defined in:
- lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb
Instance Attribute Summary collapse
-
#containing_frame ⇒ Object
Returns the value of attribute containing_frame.
-
#description ⇒ Object
Returns the value of attribute description.
-
#file_key ⇒ Object
Returns the value of attribute file_key.
-
#image_links ⇒ Object
Returns the value of attribute image_links.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#node_id ⇒ Object
Returns the value of attribute node_id.
Class Method Summary collapse
Instance Method Summary collapse
- #description_params ⇒ Object
-
#initialize(key:, file_key:, node_id:, name:, description:, containing_frame: nil, image_links: nil) ⇒ Component
constructor
A new instance of Component.
- #single_scale? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(key:, file_key:, node_id:, name:, description:, containing_frame: nil, image_links: nil) ⇒ Component
Returns a new instance of Component.
37 38 39 40 41 42 43 44 45 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 37 def initialize(key:, file_key:, node_id:, name:, description:, containing_frame: nil, image_links: nil) @key = key @file_key = file_key @node_id = node_id @name = name @description = description @containing_frame = containing_frame @image_links = image_links end |
Instance Attribute Details
#containing_frame ⇒ Object
Returns the value of attribute containing_frame.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def containing_frame @containing_frame end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def description @description end |
#file_key ⇒ Object
Returns the value of attribute file_key.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def file_key @file_key end |
#image_links ⇒ Object
Returns the value of attribute image_links.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def image_links @image_links end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def name @name end |
#node_id ⇒ Object
Returns the value of attribute node_id.
7 8 9 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 7 def node_id @node_id end |
Class Method Details
.from_hash(hash) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 47 def self.from_hash(hash) return nil if hash.nil? key = hash['key'] file_key = hash['file_key'] node_id = hash['node_id'] name = hash['name'] description = hash['description'] images_array = hash['image_links'] image_links = images_array&.map { |i| ImageLink.from_hash(i) } containing_frame = FrameInfo.from_hash(hash['containing_frame']) if !key.nil? && !file_key.nil? && !node_id.nil? && !name.nil? return Component.new( key: key, file_key: file_key, node_id: node_id, name: name, description: description, containing_frame: containing_frame, image_links: image_links ) end nil end |
Instance Method Details
#description_params ⇒ Object
31 32 33 34 35 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 31 def description_params JSON.parse(description) rescue StandardError nil end |
#single_scale? ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 16 def single_scale? links = image_links || [] return false if links.length > 1 link = links[0] return false if link.nil? image_format = link&.image_format return false if image_format.nil? scale = link.scale image_format = image_format.downcase scale == 1.0 && %w[svg pdf].include?(image_format) end |
#to_hash ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/domain/primitives/component.rb', line 74 def to_hash hash = {} hash['key'] = key hash['file_key'] = file_key hash['node_id'] = node_id hash['name'] = name hash['description'] = description hash['image_links'] = image_links&.map { |i| i.to_hash } unless image_links.nil? hash['description_params'] = description_params unless description_params.nil? hash['containing_frame'] = containing_frame&.to_hash hash end |