Sha256: 21d766d0fbd5de91803557e1ca5ed4d9c4c8f7638165f16479826c80b0a668d6

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

class PSD
  # Parses and reads all of the Resource records in the document.
  class Resources
    attr_reader :resources
    alias :data :resources
    
    def initialize(file)
      @file = file
      @resources = {}
      @type_index = {}
      @length = nil
    end

    # Parses each Resource and stores them.
    def parse
      finish = length + @file.tell

      while @file.tell < finish
        resource = Resource.new(@file)
        resource.parse

        resource_end = @file.tell + resource.size

        name = Resource::Section.factory(@file, resource)
        @resources[resource.id] = resource
        @type_index[name] = resource.id unless name.nil?

        @file.seek resource_end
      end

      @file.seek finish if @file.tell != finish
    end

    def skip
      @file.seek length, IO::SEEK_CUR
    end

    def [](id)
      if id.is_a?(Symbol)
        by_type(id)
      else
        @resources[id]
      end
    end

    def by_type(id)
      @resources[@type_index[id]]
    end

    def length
      @length ||= @file.read_int
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
psd-3.2.4 lib/psd/resources.rb
psd-3.2.3 lib/psd/resources.rb
psd-3.2.2 lib/psd/resources.rb
psd-3.2.1 lib/psd/resources.rb
psd-3.2.0 lib/psd/resources.rb
psd-3.1.5 lib/psd/resources.rb
psd-3.1.4 lib/psd/resources.rb
psd-3.1.3 lib/psd/resources.rb
psd-3.1.2 lib/psd/resources.rb