Class: PSD::Node::Root

Inherits:
Base
  • Object
show all
Defined in:
lib/psd/nodes/root.rb

Overview

Represents the root node of a Photoshop document

Defined Under Namespace

Classes: RootLayer

Constant Summary

Constants inherited from Base

Base::PROPERTIES

Instance Attribute Summary collapse

Attributes inherited from Base

#force_visible, #id, #layer, #left_offset, #name, #parent, #top_offset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#bottom, #clipping_mask, #color_label, #debug_name, #group?, #height, #hidden?, #layer?, #left, #right, #top, #visible?, #width

Methods included from Locking

#all_locked?, #any_locked?, #composite_locked?, #position_locked?, #transparency_locked?

Methods included from BuildPreview

#renderer, #save_as_png, #to_png

Methods included from LayerComps

#filter_by_comp, #position_in_comp, #visible_in_comp?

Methods included from Search

#children_at_path, #find_by_id

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.



26
27
28
29
30
31
# File 'lib/psd/nodes/root.rb', line 26

def initialize(psd)
  super self.class.layer_for_psd(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

#childrenObject

Returns the value of attribute children.



7
8
9
# File 'lib/psd/nodes/root.rb', line 7

def children
  @children
end

#psdObject (readonly)

Returns the value of attribute psd.



8
9
10
# File 'lib/psd/nodes/root.rb', line 8

def psd
  @psd
end

Class Method Details

.layer_for_psd(psd) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/psd/nodes/root.rb', line 15

def self.layer_for_psd(psd)
  RootLayer.new.tap do |layer|
    layer.top = 0
    layer.left = 0
    layer.right = psd.header.width.to_i
    layer.bottom = psd.header.height.to_i
  end
end

Instance Method Details

#depthObject

The depth of the root node is always 0.



39
40
41
# File 'lib/psd/nodes/root.rb', line 39

def depth
  0
end

#document_dimensionsObject

Returns the width and height of the entire PSD document.



34
35
36
# File 'lib/psd/nodes/root.rb', line 34

def document_dimensions
  [document_width, document_height]
end

#fill_opacityObject



44
# File 'lib/psd/nodes/root.rb', line 44

def fill_opacity; 255; end

#opacityObject



43
# File 'lib/psd/nodes/root.rb', line 43

def opacity; 255; end

#to_hashObject

Recursively exports the hierarchy to a Hash



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/psd/nodes/root.rb', line 47

def to_hash
  {
    children: children.map(&:to_hash),
    document: {
      width: document_width,
      height: document_height,
      depth: psd.header.depth,
      resources: {
        layer_comps: @psd.layer_comps,
        guides: @psd.guides,
        slices: @psd.slices.map(&:to_hash)
      }
    }
  }
end