Class: XCAssets::Image

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, filename: nil, size: nil, idiom: nil, scale: nil) ⇒ Image

Returns a new instance of Image.

Raises:

  • (IOError)


10
11
12
13
14
15
16
17
18
# File 'lib/xcassets/image.rb', line 10

def initialize(source, filename: nil, size: nil, idiom: nil, scale: nil)
  raise IOError, "#{File.absolute_path(source)} is not readable." unless File.readable?(source)

  @source = source
  @filename = filename || File.basename(source)
  @size = size || FastImage.size(source).join('x')
  @idiom = (idiom || guess_idiom).to_sym
  @scale = (scale || guess_scale).to_i
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/xcassets/image.rb', line 8

def filename
  @filename
end

#idiomObject (readonly)

Returns the value of attribute idiom.



8
9
10
# File 'lib/xcassets/image.rb', line 8

def idiom
  @idiom
end

#scaleObject (readonly)

Returns the value of attribute scale.



8
9
10
# File 'lib/xcassets/image.rb', line 8

def scale
  @scale
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/xcassets/image.rb', line 8

def size
  @size
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/xcassets/image.rb', line 8

def source
  @source
end

Instance Method Details

#contentsObject



20
21
22
23
24
25
26
27
# File 'lib/xcassets/image.rb', line 20

def contents
  {
    filename: @filename,
    size: @size,
    idiom: @idiom.to_s,
    scale: "#{@scale}x"
  }
end

#save(parent_path) ⇒ Object



29
30
31
32
# File 'lib/xcassets/image.rb', line 29

def save(parent_path)
  new_path = File.join(parent_path, filename)
  FileUtils.copy(@source, new_path)
end