Class: PSD::Node::Group
- 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
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.
- #passthru_blending? ⇒ Boolean
-
#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 HasChildren
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
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
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
10 11 12 |
# File 'lib/psd/node_group.rb', line 10 def bottom @bottom end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
10 11 12 |
# File 'lib/psd/node_group.rb', line 10 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/psd/node_group.rb', line 10 def name @name end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
10 11 12 |
# File 'lib/psd/node_group.rb', line 10 def right @right end |
#top ⇒ Object (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
#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
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
49 50 51 |
# File 'lib/psd/node_group.rb', line 49 def passthru_blending? blending_mode == 'passthru' 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.
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 |