Class: PSD::Descriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/descriptor.rb

Overview

A descriptor is a block of data that describes a complex data structure of some kind. It was added sometime around Photoshop 5.0 and it superceded a few legacy things such as layer names and type data.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Descriptor

Store a reference to our file and initialize our data structure.


7
8
9
10
# File 'lib/psd/descriptor.rb', line 7

def initialize(file)
  @file = file
  @data = {}
end

Instance Method Details

#parseObject

Parse the descriptor. Descriptors always start with a class identifier, followed by a variable number of items in the descriptor. We return the Hash that represents the full data structure.


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/psd/descriptor.rb', line 15

def parse
  PSD.logger.debug "Descriptor: pos = #{@file.tell}"

  @data[:class] = parse_class
  num_items = @file.read_int

  PSD.logger.debug "Class = #{@data[:class]}, Item count = #{num_items}"

  num_items.times do |i|
    id, value = parse_key_item
    @data[id] = value
  end

  @data
end