Class: XCRes::XCAssets::Resource

Inherits:
Object
  • Object
show all
Includes:
FileHelper
Defined in:
lib/xcres/model/xcassets/resource.rb

Overview

Represents a single resource of an asset catalog

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileHelper

#basename_without_ext

Constructor Details

#initialize(bundle, path) ⇒ Resource

Initialize a new resource

Parameters:

  • the (XCAssets:Bundle)

    containing bundle

  • see (Pathname)

    #path.



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

#bundleXCAssets::Bundle

Returns the whole bundle.

Returns:



14
15
16
# File 'lib/xcres/model/xcassets/resource.rb', line 14

def bundle
  @bundle
end

#imagesArray<XCAssets::ResourceImage>

Lazy read the images, if not initialized

Returns:



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

def images
  @images
end

#infoHash

Lazy read the info, if not initialized

Returns:

  • (Hash)


22
23
24
# File 'lib/xcres/model/xcassets/resource.rb', line 22

def info
  @info
end

#pathPathname

Returns the directory name.

Returns:

  • (Pathname)

    the directory name



18
19
20
# File 'lib/xcres/model/xcassets/resource.rb', line 18

def path
  @path
end

Instance Method Details

#nameString

Return the name of the resource

Returns:

  • (String)


45
46
47
# File 'lib/xcres/model/xcassets/resource.rb', line 45

def name
  @name ||= basename_without_ext path
end

#to_hashHash

Serialize to hash

Returns:

  • (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

#typeString

Return the type of the resource, e.g. ‘appiconset’, ‘imageset’, ‘launchimage’

Returns:

  • (String)


54
55
56
# File 'lib/xcres/model/xcassets/resource.rb', line 54

def type
  @type ||= File.extname(path).sub(/^./, '')
end