Class: PSD::Node::Group

Inherits:
PSD::Node show all
Includes:
HasChildren, LockToOrigin
Defined in:
lib/psd/node_group.rb

Overview

Represents a group, or folder, in the PSD document. It can have zero or more children nodes.

Constant Summary

Constants inherited from PSD::Node

PROPERTIES

Instance Attribute Summary collapse

Attributes inherited from PSD::Node

#children, #force_visible, #layer, #parent

Instance Method Summary collapse

Methods included from LockToOrigin

#lock_to_origin

Methods included from HasChildren

#groups, #layers

Methods inherited from PSD::Node

#debug_name, #document_dimensions, #group?, #hidden?, #layer?, #psd, #visible?

Methods included from BuildPreview

#renderer, #save_as_png, #to_png

Methods included from Search

#children_at_path, #filter_by_comp

Methods included from Ancestry

#ancestors, #childless?, #depth, #descendants, #has_children?, #has_siblings?, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree

Methods included from ParseLayers

#parse_layers

Constructor Details

#initialize(folder) ⇒ Group

Parses the descendant tree structure and figures out the bounds of the layers within this folder.



14
15
16
17
18
19
20
# File 'lib/psd/node_group.rb', line 14

def initialize(folder)
  @name = folder[:name]
  @layer = folder[:layer]
  
  super(folder[:layers])
  get_dimensions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If the method is missing, we blindly send it to the layer. The layer handles the case in which the method doesn’t exist.



72
73
74
# File 'lib/psd/node_group.rb', line 72

def method_missing(method, *args, &block)
  @layer.send(method, *args, &block)
end

Instance Attribute Details

#bottomObject (readonly)

Returns the value of attribute bottom.



10
11
12
# File 'lib/psd/node_group.rb', line 10

def bottom
  @bottom
end

#leftObject (readonly)

Returns the value of attribute left.



10
11
12
# File 'lib/psd/node_group.rb', line 10

def left
  @left
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/psd/node_group.rb', line 10

def name
  @name
end

#rightObject (readonly)

Returns the value of attribute right.



10
11
12
# File 'lib/psd/node_group.rb', line 10

def right
  @right
end

#topObject (readonly)

Returns the value of attribute top.



10
11
12
# File 'lib/psd/node_group.rb', line 10

def top
  @top
end

Instance Method Details

#colsObject Also known as: width

Calculated width of this folder.



29
30
31
# File 'lib/psd/node_group.rb', line 29

def cols
  @right - @left
end

#empty?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/psd/node_group.rb', line 53

def empty?
  @children.each do |child|
    return false unless child.empty?
  end
  
  return true
end

#hide!Object

Attempt to hide all children of this layer.



40
41
42
# File 'lib/psd/node_group.rb', line 40

def hide!
  @children.each{ |c| c.hide! }
end

#passthru_blending?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/psd/node_group.rb', line 49

def passthru_blending?
  blending_mode == 'passthru'
end

#rowsObject Also known as: height

Calculated height of this folder.



23
24
25
# File 'lib/psd/node_group.rb', line 23

def rows
  @bottom - @top
end

#show!Object

Attempt to show all children of this layer.



45
46
47
# File 'lib/psd/node_group.rb', line 45

def show!
  @children.each{ |c| c.show! }
end

#to_hashObject

Export this layer and it’s children to a hash recursively.



62
63
64
65
66
67
68
# File 'lib/psd/node_group.rb', line 62

def to_hash
  super.merge({
    type: :group,
    visible: visible?,
    children: children.map(&:to_hash)
  })
end

#translate(x = 0, y = 0) ⇒ Object

Attempt to translate this folder and all of the descendants.



35
36
37
# File 'lib/psd/node_group.rb', line 35

def translate(x=0, y=0)
  @children.each{ |c| c.translate(x,y) }
end