Class: XCRes::XCAssets::ResourceImage
- Inherits:
-
Object
- Object
- XCRes::XCAssets::ResourceImage
- Defined in:
- lib/xcres/model/xcassets/resource_image.rb
Overview
Represents a single image of a resource in an asset catalog
Constant Summary collapse
- KNOWN_KEYS =
The known keys
[ :filename, :scale, :orientation, :size, :idiom, :subtype, :extent, :minimum_system_version ].freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{Symbol => String}
Further attributes, not mapped to a specific attribute.
-
#extent ⇒ Symbol
The extent, e.g.
-
#filename ⇒ Pathname
File name.
-
#idiom ⇒ Symbol
The idiom, e.g.
-
#minimum_system_version ⇒ String
The minimum system version, e.g.
-
#orientation ⇒ Symbol
The orientation, e.g.
-
#scale ⇒ Integer
Scale of the image.
-
#size ⇒ String
The size, e.g.
-
#subtype ⇒ Symbol
The subtype, e.g.
Class Method Summary collapse
-
.read(hash) ⇒ ResourceImage
Read from hash.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(attributes = {}) ⇒ ResourceImage
constructor
Initialize a new ResourceImage.
-
#read(hash) ⇒ ResourceImage
Read from hash.
-
#to_hash ⇒ Hash{String => String}
Serialize to hash.
Constructor Details
#initialize(attributes = {}) ⇒ ResourceImage
Initialize a new ResourceImage
73 74 75 76 77 78 79 80 81 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 73 def initialize(attributes={}) self.scale = attributes.delete('scale') unless attributes['scale'].nil? KNOWN_KEYS.each do |key| self.send "#{key}=".to_sym, attributes.delete(key) end self.attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Hash{Symbol => String}
Returns further attributes, not mapped to a specific attribute.
55 56 57 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 55 def attributes @attributes end |
#extent ⇒ Symbol
Returns the extent, e.g. ‘full-screen’.
47 48 49 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 47 def extent @extent end |
#filename ⇒ Pathname
Returns file name.
23 24 25 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 23 def filename @filename end |
#idiom ⇒ Symbol
Returns the idiom, e.g. ‘iphone’.
39 40 41 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 39 def idiom @idiom end |
#minimum_system_version ⇒ String
Returns the minimum system version, e.g. ‘7.0’.
51 52 53 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 51 def minimum_system_version @minimum_system_version end |
#orientation ⇒ Symbol
Returns the orientation, e.g. ‘portrait’.
31 32 33 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 31 def orientation @orientation end |
#scale ⇒ Integer
Returns scale of the image.
27 28 29 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 27 def scale @scale end |
#size ⇒ String
Returns the size, e.g. ‘29x29’, ‘40x40’.
35 36 37 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 35 def size @size end |
#subtype ⇒ Symbol
Returns the subtype, e.g. ‘retina4’.
43 44 45 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 43 def subtype @subtype end |
Class Method Details
.read(hash) ⇒ ResourceImage
Read from hash
64 65 66 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 64 def self.read(hash) self.new.read(hash) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
125 126 127 128 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 125 def ==(other) return false unless other.respond_to?(:to_hash) self.to_hash == other.to_hash end |
#read(hash) ⇒ ResourceImage
Read from hash
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 90 def read(hash) self.scale = hash.delete('scale').sub(/x$/, '').to_i unless hash['scale'].nil? KNOWN_KEYS.each do |key| value = hash.delete(key.to_s.dasherize) next if value.nil? self.send "#{key}=".to_sym, value end self.attributes = hash return self end |
#to_hash ⇒ Hash{String => String}
Serialize to hash
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/xcres/model/xcassets/resource_image.rb', line 108 def to_hash hash = {} hash['scale'] = "#{scale}x" unless scale.nil? (KNOWN_KEYS - [:scale]).each do |key| value = self.send(key) hash[key.to_s.dasherize] = value.to_s unless value.nil? end attributes.each do |key, value| hash[key.to_s] = value end hash end |