Class: PSD::Node
- Inherits:
-
Object
- Object
- PSD::Node
- Defined in:
- lib/psd/node.rb,
lib/psd/node_root.rb,
lib/psd/node_group.rb,
lib/psd/node_layer.rb,
lib/psd/nodes/search.rb,
lib/psd/nodes/ancestry.rb,
lib/psd/nodes/parse_layers.rb,
lib/psd/nodes/lock_to_origin.rb
Defined Under Namespace
Modules: Ancestry, LockToOrigin, ParseLayers, Search Classes: Group, Layer, Root
Constant Summary collapse
- PROPERTIES =
Default properties that all nodes contain
[:name, :left, :right, :top, :bottom, :height, :width]
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #document_dimensions ⇒ Object
- #hidden? ⇒ Boolean
-
#initialize(layers = []) ⇒ Node
constructor
A new instance of Node.
- #to_hash ⇒ Object
- #visible? ⇒ Boolean
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(layers = []) ⇒ Node
Returns a new instance of Node.
16 17 18 19 20 21 22 |
# File 'lib/psd/node.rb', line 16 def initialize(layers=[]) @children = [] layers.each do |layer| layer.parent = self @children << layer end 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.
14 15 16 |
# File 'lib/psd/node.rb', line 14 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
14 15 16 |
# File 'lib/psd/node.rb', line 14 def parent @parent end |
Instance Method Details
#document_dimensions ⇒ Object
47 48 49 |
# File 'lib/psd/node.rb', line 47 def document_dimensions @parent.document_dimensions end |
#hidden? ⇒ Boolean
24 25 26 |
# File 'lib/psd/node.rb', line 24 def hidden? !@layer.visible? end |
#to_hash ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/psd/node.rb', line 32 def to_hash hash = { type: nil, visible: visible?, opacity: @layer.opacity / 255.0, blending_mode: @layer.blending_mode } PROPERTIES.each do |p| hash[p] = self.send(p) end hash end |
#visible? ⇒ Boolean
28 29 30 |
# File 'lib/psd/node.rb', line 28 def visible? @layer.visible? end |