Class: PSD::Node::Layer

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/psd/nodes/layer.rb

Constant Summary

Constants inherited from Base

Base::PROPERTIES

Instance Attribute Summary collapse

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

#bottom, #clipping_mask, #color_label, #debug_name, #group?, #height, #hidden?, #initialize, #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?, #depth, #descendants, #has_children?, #has_siblings?, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree

Constructor Details

This class inherits a constructor from PSD::Node::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If the method is missing, we blindly send it to the layer. The layer handles the case in which the method doesn’t exist.



40
41
42
# File 'lib/psd/nodes/layer.rb', line 40

def method_missing(method, *args, &block)
  @layer.send(method, *args, &block)
end

Instance Attribute Details

#layerObject (readonly)

Returns the value of attribute layer.



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

def layer
  @layer
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/psd/nodes/layer.rb', line 13

def empty?
  width == 0 || height == 0
end

#reference_pointObject

In case the layer doesn’t have a reference point



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

def reference_point
  @layer.reference_point || Struct.new(:x, :y).new(0, 0)
end

#to_hashObject

Exports this layer to a Hash.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/psd/nodes/layer.rb', line 18

def to_hash
  super.merge({
    type: :layer,
    text: @layer.text,
    ref_x: reference_point.x,
    ref_y: reference_point.y,
    mask: @layer.mask.to_hash,
    image: {
      width: @layer.image.width,
      height: @layer.image.height,
      channels: @layer.channels_info
    }
  })
end