Sha256: 64519efd7d338bbd699e8e0a1edc8d655f457d3c3c6c850495e66ad469cbb8dd

Contents?: true

Size: 1012 Bytes

Versions: 8

Compression:

Stored size: 1012 Bytes

Contents

require_relative 'nodes/ancestry'
require_relative 'nodes/search'

# Internal structure to help us build trees of a Photoshop documents.
# A lot of method names borrowed from the Ruby ancestry gem.
class PSD
  class Node
    include Ancestry
    include Search

    # Default properties that all nodes contain
    PROPERTIES = [:name, :left, :right, :top, :bottom, :height, :width]

    attr_accessor :parent, :children

    def initialize(layers=[])
      @children = []
      layers.each do |layer|
        layer.parent = self
        @children << layer
      end
    end

    def hidden?
      !@layer.visible?
    end

    def visible?
      @layer.visible?
    end

    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

    def document_dimensions
      @parent.document_dimensions
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
psd-1.0.0 lib/psd/node.rb
psd-0.4.2 lib/psd/node.rb
psd-0.4.1 lib/psd/node.rb
psd-0.4.0 lib/psd/node.rb
psd-0.3.5 lib/psd/node.rb
psd-0.3.4 lib/psd/node.rb
psd-0.3.3 lib/psd/node.rb
psd-0.3.2 lib/psd/node.rb