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
Returns the value of attribute children.
-
#psd ⇒ Object
readonly
Returns the value of attribute psd.
Attributes inherited from PSD::Node
#force_visible, #layer, #left, #parent, #top
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
(also: #height)
The height of the full PSD document as defined in the header.
-
#document_width ⇒ Object
(also: #width)
The width of the full PSD document as defined in the header.
- #fill_opacity ⇒ Object
-
#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.
- #opacity ⇒ Object
-
#to_hash ⇒ Object
Recursively exports the hierarchy to a Hash.
Methods included from ParseLayers
Methods included from HasChildren
Methods inherited from PSD::Node
#debug_name, #group?, #hidden?, #layer?, #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?, #descendants, #has_children?, #has_siblings?, #method_missing, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree
Constructor Details
#initialize(psd) ⇒ Root
Stores a reference to the parsed PSD and builds the tree hierarchy.
14 15 16 17 |
# File 'lib/psd/node_root.rb', line 14 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
Returns the value of attribute children.
9 10 11 |
# File 'lib/psd/node_root.rb', line 9 def children @children end |
#psd ⇒ Object (readonly)
Returns the value of attribute psd.
10 11 12 |
# File 'lib/psd/node_root.rb', line 10 def psd @psd end |
Instance Method Details
#depth ⇒ Object
The depth of the root node is always 0.
58 59 60 |
# File 'lib/psd/node_root.rb', line 58 def depth 0 end |
#document_dimensions ⇒ Object
Returns the width and height of the entire PSD document.
36 37 38 |
# File 'lib/psd/node_root.rb', line 36 def document_dimensions [document_width, document_height] end |
#document_height ⇒ Object Also known as: height
The height of the full PSD document as defined in the header.
47 48 49 |
# File 'lib/psd/node_root.rb', line 47 def document_height @psd.header.height.to_i end |
#document_width ⇒ Object Also known as: width
The width of the full PSD document as defined in the header.
41 42 43 |
# File 'lib/psd/node_root.rb', line 41 def document_width @psd.header.width.to_i end |
#fill_opacity ⇒ Object
67 |
# File 'lib/psd/node_root.rb', line 67 def fill_opacity; 255; end |
#name ⇒ Object
The root node has no name since it’s not an actual layer or group.
53 54 55 |
# File 'lib/psd/node_root.rb', line 53 def name nil end |
#opacity ⇒ Object
66 |
# File 'lib/psd/node_root.rb', line 66 def opacity; 255; end |
#to_hash ⇒ Object
Recursively exports the hierarchy to a Hash
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/psd/node_root.rb', line 20 def to_hash { children: children.map(&:to_hash), document: { width: document_width, height: document_height, resources: { layer_comps: @psd.layer_comps, guides: @psd.guides, slices: @psd.slices } } } end |