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 LayerComps

#filter_by_comp, #position_in_comp, #visible_in_comp?

Methods included from Search

#children_at_path

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.



50
51
52
# File 'lib/psd/nodes/layer.rb', line 50

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

#reference_pointObject

In case the layer doesn’t have a reference point



44
45
46
# File 'lib/psd/nodes/layer.rb', line 44

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
32
33
34
35
36
37
38
39
40
41
# File 'lib/psd/nodes/layer.rb', line 18

def to_hash
  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
    },
    layer_comps: {}
  })

  root.psd.layer_comps.each do |comp|
    hash[:layer_comps][comp[:name]] = {
      visible: visible_in_comp?(comp[:id]),
      position: position_in_comp(comp[:id])
    }
  end

  hash
end