Class: PSD::Node::Root
- Includes:
- HasChildren, ParseLayers
- Defined in:
- lib/psd/node_root.rb
Overview
Represents the root node of a Photoshop document
Constant Summary
Constants inherited from PSD::Node
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Attributes inherited from PSD::Node
Instance Method Summary collapse
-
#depth ⇒ Object
The depth of the root node is always 0.
-
#document_dimensions ⇒ Object
Returns the width and height of the entire PSD document.
-
#document_height ⇒ Object
The height of the full PSD document as defined in the header.
-
#document_width ⇒ Object
The width of the full PSD document as defined in the header.
-
#initialize(psd) ⇒ Root
constructor
Stores a reference to the parsed PSD and builds the tree hierarchy.
-
#name ⇒ Object
The root node has no name since it’s not an actual layer or group.
-
#to_hash ⇒ Object
Recursively exports the hierarchy to a Hash.
Methods included from ParseLayers
Methods included from HasChildren
Methods inherited from PSD::Node
#group?, #hidden?, #layer?, #visible?
Methods included from Search
Methods included from Ancestry
#ancestors, #childless?, #descendants, #has_children?, #has_siblings?, #method_missing, #only_child?, #root, #root?, #siblings, #subtree
Constructor Details
#initialize(psd) ⇒ Root
Stores a reference to the parsed PSD and builds the tree hierarchy.
13 14 15 16 |
# File 'lib/psd/node_root.rb', line 13 def initialize(psd) @psd = psd build_hierarchy end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PSD::Node::Ancestry
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/psd/node_root.rb', line 9 def children @children end |
Instance Method Details
#depth ⇒ Object
The depth of the root node is always 0.
50 51 52 |
# File 'lib/psd/node_root.rb', line 50 def depth 0 end |
#document_dimensions ⇒ Object
Returns the width and height of the entire PSD document.
30 31 32 |
# File 'lib/psd/node_root.rb', line 30 def document_dimensions [@psd.header.width, @psd.header.height] end |
#document_height ⇒ Object
The height of the full PSD document as defined in the header.
40 41 42 |
# File 'lib/psd/node_root.rb', line 40 def document_height @psd.header.height.to_i end |
#document_width ⇒ Object
The width of the full PSD document as defined in the header.
35 36 37 |
# File 'lib/psd/node_root.rb', line 35 def document_width @psd.header.width.to_i end |
#name ⇒ Object
The root node has no name since it’s not an actual layer or group.
45 46 47 |
# File 'lib/psd/node_root.rb', line 45 def name nil end |
#to_hash ⇒ Object
Recursively exports the hierarchy to a Hash
19 20 21 22 23 24 25 26 27 |
# File 'lib/psd/node_root.rb', line 19 def to_hash { children: children.map(&:to_hash), document: { width: document_width, height: document_height } } end |