Class: XCRes::XCAssets::Resource
- Inherits:
-
Object
- Object
- XCRes::XCAssets::Resource
- Includes:
- FileHelper
- Defined in:
- lib/xcres/model/xcassets/resource.rb
Overview
Represents a single resource of an asset catalog
Instance Attribute Summary collapse
-
#bundle ⇒ XCAssets::Bundle
The whole bundle.
-
#images ⇒ Array<XCAssets::ResourceImage>
Lazy read the images, if not initialized.
-
#info ⇒ Hash
Lazy read the info, if not initialized.
-
#path ⇒ Pathname
The directory name.
Instance Method Summary collapse
-
#initialize(bundle, path) ⇒ Resource
constructor
Initialize a new resource.
-
#name ⇒ String
Return the name of the resource.
-
#to_hash ⇒ Hash
Serialize to hash.
-
#type ⇒ String
Return the type of the resource, e.g.
Methods included from FileHelper
Constructor Details
#initialize(bundle, path) ⇒ Resource
Initialize a new resource
36 37 38 39 |
# File 'lib/xcres/model/xcassets/resource.rb', line 36 def initialize(bundle, path) self.bundle = bundle self.path = path end |
Instance Attribute Details
#bundle ⇒ XCAssets::Bundle
Returns the whole bundle.
14 15 16 |
# File 'lib/xcres/model/xcassets/resource.rb', line 14 def bundle @bundle end |
#images ⇒ Array<XCAssets::ResourceImage>
Lazy read the images, if not initialized
26 27 28 |
# File 'lib/xcres/model/xcassets/resource.rb', line 26 def images @images end |
#info ⇒ Hash
Lazy read the info, if not initialized
22 23 24 |
# File 'lib/xcres/model/xcassets/resource.rb', line 22 def info @info end |
#path ⇒ Pathname
Returns the directory name.
18 19 20 |
# File 'lib/xcres/model/xcassets/resource.rb', line 18 def path @path end |
Instance Method Details
#name ⇒ String
Return the name of the resource
45 46 47 |
# File 'lib/xcres/model/xcassets/resource.rb', line 45 def name @name ||= basename_without_ext path end |
#to_hash ⇒ Hash
Serialize to hash
78 79 80 81 82 83 |
# File 'lib/xcres/model/xcassets/resource.rb', line 78 def to_hash { 'images' => images.map(&:to_hash), 'info' => info, } end |
#type ⇒ String
Return the type of the resource, e.g. ‘appiconset’, ‘imageset’, ‘launchimage’
54 55 56 |
# File 'lib/xcres/model/xcassets/resource.rb', line 54 def type @type ||= File.extname(path).sub(/^./, '') end |