Class: XCRes::XCAssets::Bundle

Inherits:
Object
  • Object
show all
Defined in:
lib/xcres/model/xcassets/bundle.rb

Overview

Represents the whole asset catalog

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Bundle

Initialize a new file with given path

Parameters:

  • path (Pathname) (defaults to: nil)

    the location of the container



35
36
37
38
# File 'lib/xcres/model/xcassets/bundle.rb', line 35

def initialize(path = nil)
  @path = Pathname(path) unless path.nil?
  @resources = []
end

Instance Attribute Details

#pathPathname

Returns:

  • (Pathname)


11
12
13
# File 'lib/xcres/model/xcassets/bundle.rb', line 11

def path
  @path
end

#resource_pathsArray<Pathname>

Returns the paths of the resources contained, relative to the container given by #path.

Returns:

  • (Array<Pathname>)

    the paths of the resources contained, relative to the container given by #path.



16
17
18
# File 'lib/xcres/model/xcassets/bundle.rb', line 16

def resource_paths
  @resource_paths
end

#resourcesArray<Resource>

Returns the parsed resources.

Returns:

  • (Array<Resource>)

    the parsed resources



20
21
22
# File 'lib/xcres/model/xcassets/bundle.rb', line 20

def resources
  @resources
end

Class Method Details

.open(path) ⇒ XCAssets::Bundle

Open a XCAssets collection at a given path

Returns:



26
27
28
# File 'lib/xcres/model/xcassets/bundle.rb', line 26

def self.open(path)
  self.new(path).read
end

Instance Method Details

#readXCAssets::Bundle

Read the resources from disk

Returns:



44
45
46
47
48
49
50
51
52
# File 'lib/xcres/model/xcassets/bundle.rb', line 44

def read
  @resource_paths = Dir.chdir(path) do
    Dir['**/Contents.json'].map { |p| Pathname(p) + '..' }
  end
  @resources = @resource_paths.map do |path|
    Resource.new(self, path)
  end
  self
end