Class: PSD::Slice
- Inherits:
-
Object
- Object
- PSD::Slice
- Defined in:
- lib/psd/slice.rb
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#associated_layer_id ⇒ Object
readonly
Returns the value of attribute associated_layer_id.
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#cell_text ⇒ Object
readonly
Returns the value of attribute cell_text.
-
#cell_text_is_html ⇒ Object
readonly
Returns the value of attribute cell_text_is_html.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
-
#horizontal_alignment ⇒ Object
readonly
Returns the value of attribute horizontal_alignment.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#outset ⇒ Object
readonly
Returns the value of attribute outset.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#vertical_alignment ⇒ Object
readonly
Returns the value of attribute vertical_alignment.
Instance Method Summary collapse
- #associated_layer ⇒ Object
- #height ⇒ Object
-
#initialize(psd, data) ⇒ Slice
constructor
A new instance of Slice.
- #save_as_png(file) ⇒ Object
- #to_hash ⇒ Object
- #to_png ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(psd, data) ⇒ Slice
Returns a new instance of Slice.
8 9 10 11 12 13 14 |
# File 'lib/psd/slice.rb', line 8 def initialize(psd, data) @psd = psd @keys = data.keys data.each do |k, v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def alt @alt end |
#associated_layer_id ⇒ Object (readonly)
Returns the value of attribute associated_layer_id.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def associated_layer_id @associated_layer_id end |
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def bounds @bounds end |
#cell_text ⇒ Object (readonly)
Returns the value of attribute cell_text.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def cell_text @cell_text end |
#cell_text_is_html ⇒ Object (readonly)
Returns the value of attribute cell_text_is_html.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def cell_text_is_html @cell_text_is_html end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def color @color end |
#group_id ⇒ Object (readonly)
Returns the value of attribute group_id.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def group_id @group_id end |
#horizontal_alignment ⇒ Object (readonly)
Returns the value of attribute horizontal_alignment.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def horizontal_alignment @horizontal_alignment end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def id @id end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def @message end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def name @name end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def origin @origin end |
#outset ⇒ Object (readonly)
Returns the value of attribute outset.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def outset @outset end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def target @target end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def url @url end |
#vertical_alignment ⇒ Object (readonly)
Returns the value of attribute vertical_alignment.
3 4 5 |
# File 'lib/psd/slice.rb', line 3 def vertical_alignment @vertical_alignment end |
Instance Method Details
#associated_layer ⇒ Object
28 29 30 |
# File 'lib/psd/slice.rb', line 28 def associated_layer @psd.tree.find_by_id(associated_layer_id) end |
#height ⇒ Object
24 25 26 |
# File 'lib/psd/slice.rb', line 24 def height bottom - top end |
#save_as_png(file) ⇒ Object
36 37 38 |
# File 'lib/psd/slice.rb', line 36 def save_as_png(file) @png.save(file, :fast_rgba) end |
#to_hash ⇒ Object
40 41 42 |
# File 'lib/psd/slice.rb', line 40 def to_hash Hash[@keys.map { |k| [k.to_sym, self.send(k)] }] end |
#to_png ⇒ Object
32 33 34 |
# File 'lib/psd/slice.rb', line 32 def to_png @png ||= @psd.image.to_png.crop(left, top, width, height) end |
#width ⇒ Object
20 21 22 |
# File 'lib/psd/slice.rb', line 20 def width right - left end |