Class: PSD::Resources
- Inherits:
-
Object
- Object
- PSD::Resources
- Defined in:
- lib/psd/resources.rb
Overview
Parses and reads all of the Resource records in the document.
Instance Attribute Summary collapse
-
#resources ⇒ Object
(also: #data)
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #by_type(id) ⇒ Object
-
#initialize(file) ⇒ Resources
constructor
A new instance of Resources.
- #length ⇒ Object
-
#parse ⇒ Object
Parses each Resource and stores them.
- #skip ⇒ Object
Constructor Details
#initialize(file) ⇒ Resources
Returns a new instance of Resources.
11 12 13 14 15 16 |
# File 'lib/psd/resources.rb', line 11 def initialize(file) @file = file @resources = {} @type_index = {} @length = nil end |
Instance Attribute Details
#resources ⇒ Object (readonly) Also known as: data
Returns the value of attribute resources.
8 9 10 |
# File 'lib/psd/resources.rb', line 8 def resources @resources end |
Instance Method Details
#[](id) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/psd/resources.rb', line 42 def [](id) if id.is_a?(Symbol) by_type(id) else @resources[id] end end |
#by_type(id) ⇒ Object
50 51 52 |
# File 'lib/psd/resources.rb', line 50 def by_type(id) @resources[@type_index[id]] end |
#length ⇒ Object
54 55 56 |
# File 'lib/psd/resources.rb', line 54 def length @length ||= @file.read_int end |
#parse ⇒ Object
Parses each Resource and stores them.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/psd/resources.rb', line 19 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 |
#skip ⇒ Object
38 39 40 |
# File 'lib/psd/resources.rb', line 38 def skip @file.seek length, IO::SEEK_CUR end |