Class: FigmaNodesResult

Inherits:
Object
  • Object
show all
Defined in:
lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, nodes:) ⇒ FigmaNodesResult

Returns a new instance of FigmaNodesResult.



8
9
10
11
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 8

def initialize(name:, nodes:)
  @name = name
  @nodes = nodes
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 6

def name
  @name
end

#nodesObject

Returns the value of attribute nodes.



6
7
8
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 6

def nodes
  @nodes
end

Class Method Details

.from_hash(hash) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 13

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

  name = hash['name']
  nodes = FigmaNodesResult.parse_nodes(hash: hash['nodes'])

  return FigmaNodesResult.new(name: name, nodes: nodes) if !name.nil? && !nodes.nil?

  nil
end

.parse_nodes(hash:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 39

def self.parse_nodes(hash:)
  return nil if hash.nil?

  result_hash = {}

  hash.each do |k, v|
    node_hash = v['document']
    node = FigmaNode.from_hash(node_hash)
    result_hash[k] = { 'document' => node } unless node.nil?
  end

  result_hash
end

Instance Method Details

#to_hashObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/admiral-tools-figma/helper/figma/figma_client/models/api/results/figma_nodes_result.rb', line 24

def to_hash
  hash = {}
  hash['name'] = name
  nodes_hash = (nodes || {})
  nodes_result_hash = {}

  nodes_hash.each do |k, v|
    node = v['document'].to_hash
    nodes_result_hash[k] = { 'document' => node } unless node.nil?
  end

  hash['nodes'] = nodes_result_hash
  hash
end