Class: PSD::Node::Layer

Inherits:
Base
  • Object
show all
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, #left_offset, #name, #parent, #top_offset

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from BuildPreview

#renderer, #save_as_png, #to_png

Methods included from Search

#children_at_path, #filter_by_comp

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.



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

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

Instance Attribute Details

#layerObject (readonly)

Returns the value of attribute layer.



6
7
8
# File 'lib/psd/nodes/layer.rb', line 6

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

#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: @layer.reference_point.x,
    ref_y: @layer.reference_point.y,
    mask: @layer.mask.to_hash,
    image: {
      width: @layer.image.width,
      height: @layer.image.height,
      channels: @layer.channels_info
    }
  })
end