Class: XCAssets::Image
- Inherits:
-
Object
- Object
- XCAssets::Image
- Defined in:
- lib/xcassets/image.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#idiom ⇒ Object
readonly
Returns the value of attribute idiom.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #contents ⇒ Object
-
#initialize(source, filename: nil, size: nil, idiom: nil, scale: nil) ⇒ Image
constructor
A new instance of Image.
- #save(parent_path) ⇒ Object
Constructor Details
#initialize(source, filename: nil, size: nil, idiom: nil, scale: nil) ⇒ Image
Returns a new instance of Image.
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/xcassets/image.rb', line 8 def filename @filename end |
#idiom ⇒ Object (readonly)
Returns the value of attribute idiom.
8 9 10 |
# File 'lib/xcassets/image.rb', line 8 def idiom @idiom end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
8 9 10 |
# File 'lib/xcassets/image.rb', line 8 def scale @scale end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/xcassets/image.rb', line 8 def size @size end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/xcassets/image.rb', line 8 def source @source end |
Instance Method Details
#contents ⇒ Object
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 |