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
#children, #force_visible, #layer, #parent
Instance Method Summary collapse
-
#cols ⇒ Object
(also: #width)
Calculated width of this folder.
- #empty? ⇒ Boolean
-
#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.
-
#method_missing(method, *args, &block) ⇒ Object
If the method is missing, we blindly send it to the layer.
-
#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, #group?, #hidden?, #layer?, #psd, #visible?
Methods included from BuildPreview
#build_png, #orig_to_png, #to_png
Methods included from Image::Export::PNG
#mask_to_png, #save_as_png, #to_png, #to_png_with_mask
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
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
#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.
64 65 66 |
# File 'lib/psd/node_group.rb', line 64 def method_missing(method, *args, &block) @layer.send(method, *args, &block) end |
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 @right - @left end |
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/psd/node_group.rb', line 49 def empty? @children.empty? 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 @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_hash ⇒ Object
Export this layer and it’s children to a hash recursively.
54 55 56 57 58 59 60 |
# File 'lib/psd/node_group.rb', line 54 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 |