Class: PSD::Node::Group
- 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
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Attributes inherited from PSD::Node
Instance Method Summary collapse
-
#cols ⇒ Object
(also: #width)
Calculated width of this folder.
-
#hide! ⇒ Object
Attempt to hide all children of this layer.
-
#initialize(folder) ⇒ Group
constructor
Parses the descendant tree structure and figures out the bounds of the layers within this folder.
-
#rows ⇒ Object
(also: #height)
Calculated height of this folder.
-
#show! ⇒ Object
Attempt to show all children of this layer.
-
#to_hash ⇒ Object
Export this layer and it’s children to a hash recursively.
-
#translate(x = 0, y = 0) ⇒ Object
Attempt to translate this folder and all of the descendants.
Methods included from LockToOrigin
Methods included from ParseLayers
Methods included from HasChildren
Methods inherited from PSD::Node
#document_dimensions, #hidden?, #visible?
Methods included from Search
Methods included from Ancestry
#ancestors, #depth, #descendants, #has_children?, #has_siblings?, #is_childless?, #is_only_child?, #method_missing, #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
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
11 12 13 |
# File 'lib/psd/node_group.rb', line 11 def bottom @bottom end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
11 12 13 |
# File 'lib/psd/node_group.rb', line 11 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/psd/node_group.rb', line 11 def name @name end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
11 12 13 |
# File 'lib/psd/node_group.rb', line 11 def right @right end |
#top ⇒ Object (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
#cols ⇒ Object 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 |
#rows ⇒ Object 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_hash ⇒ Object
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 |