Class: PSD::Node::Group

Inherits:
PSD::Node show all
Includes:
HasChildren, LockToOrigin, ParseLayers
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, #parent

Instance Method Summary collapse

Methods included from LockToOrigin

#lock_to_origin

Methods included from ParseLayers

#parse_layers

Methods included from HasChildren

#groups, #layers

Methods inherited from PSD::Node

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

Methods included from Search

#children_at_path

Methods included from Ancestry

#ancestors, #childless?, #depth, #descendants, #has_children?, #has_siblings?, #method_missing, #only_child?, #root, #root?, #siblings, #subtree

Constructor Details

#initialize(folder) ⇒ Group

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



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PSD::Node::Ancestry

Instance Attribute Details

#bottomObject (readonly)

Returns the value of attribute bottom.



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

def bottom
  @bottom
end

#leftObject (readonly)

Returns the value of attribute left.



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

def left
  @left
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

#topObject (readonly)

Returns the value of attribute top.



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

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
  @bottom - @top
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

#rowsObject Also known as: height

Calculated height of this folder.



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

def rows
  @right - @left
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.



50
51
52
53
54
55
56
# File 'lib/psd/node_group.rb', line 50

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