Class: PSD::Node

Inherits:
Object
  • Object
show all
Includes:
Ancestry, BuildPreview, Search
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/build_preview.rb,
lib/psd/nodes/lock_to_origin.rb

Direct Known Subclasses

Group, Layer, Root

Defined Under Namespace

Modules: Ancestry, BuildPreview, 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

Instance Method Summary collapse

Methods included from BuildPreview

#build_png, #orig_to_png, #to_png

Methods included from Image::Export::PNG

#mask_to_png, #save_as_png, #to_png, #to_png_with_mask

Methods included from Search

#children_at_path, #filter_by_comp

Methods included from Ancestry

#ancestors, #childless?, #depth, #descendants, #has_children?, #has_siblings?, #method_missing, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree

Constructor Details

#initialize(layers = []) ⇒ Node

Returns a new instance of Node.



17
18
19
20
21
22
23
# File 'lib/psd/node.rb', line 17

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

#childrenObject

Returns the value of attribute children.



15
16
17
# File 'lib/psd/node.rb', line 15

def children
  @children
end

#layerObject

Returns the value of attribute layer.



15
16
17
# File 'lib/psd/node.rb', line 15

def layer
  @layer
end

#parentObject

Returns the value of attribute parent.



15
16
17
# File 'lib/psd/node.rb', line 15

def parent
  @parent
end

Instance Method Details

#document_dimensionsObject



60
61
62
# File 'lib/psd/node.rb', line 60

def document_dimensions
  @parent.document_dimensions
end

#group?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/psd/node.rb', line 41

def group?
  is_a?(PSD::Node::Group) || is_a?(PSD::Node::Root)
end

#hidden?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/psd/node.rb', line 25

def hidden?
  !@layer.visible?
end

#layer?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/psd/node.rb', line 37

def layer?
  is_a?(PSD::Node::Layer)
end

#psdObject



33
34
35
# File 'lib/psd/node.rb', line 33

def psd
  parent.psd
end

#to_hashObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/psd/node.rb', line 45

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/psd/node.rb', line 29

def visible?
  @layer.visible?
end