Class: XCAssets::Iconset

Inherits:
Object
  • Object
show all
Defined in:
lib/xcassets/iconset.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, author: 'xcassets', version: 1) ⇒ Iconset

Returns a new instance of Iconset.



9
10
11
12
13
14
# File 'lib/xcassets/iconset.rb', line 9

def initialize(name, author: 'xcassets', version: 1)
  @name = name
  @images = []
  @author = author
  @version = version
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



7
8
9
# File 'lib/xcassets/iconset.rb', line 7

def author
  @author
end

#imagesObject (readonly)

Returns the value of attribute images.



7
8
9
# File 'lib/xcassets/iconset.rb', line 7

def images
  @images
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/xcassets/iconset.rb', line 7

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/xcassets/iconset.rb', line 7

def version
  @version
end

Instance Method Details

#add(image) ⇒ Object



26
27
28
# File 'lib/xcassets/iconset.rb', line 26

def add(image)
  @images << image
end

#contentsObject



20
21
22
23
24
# File 'lib/xcassets/iconset.rb', line 20

def contents
  @images.each_with_object(info: info, images: []) do |image, hash|
    hash[:images] << image.contents
  end
end

#infoObject



16
17
18
# File 'lib/xcassets/iconset.rb', line 16

def info
  { author: @author, version: @version }
end

#save(parent_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/xcassets/iconset.rb', line 30

def save(parent_path)
  path = File.join(parent_path, "#{name}.iconset")
  Dir.mkdir(path)
  @images.each do |image|
    image.save(path)
  end
  json_path = File.join(path, 'Contents.json')
  File.open(json_path, 'w') do |file|
    JSON.dump(contents, file)
  end
end