Class: PSD::Slice

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/slice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#altObject (readonly)

Returns the value of attribute alt


3
4
5
# File 'lib/psd/slice.rb', line 3

def alt
  @alt
end

#associated_layer_idObject (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

#boundsObject (readonly)

Returns the value of attribute bounds


3
4
5
# File 'lib/psd/slice.rb', line 3

def bounds
  @bounds
end

#cell_textObject (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_htmlObject (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

#colorObject (readonly)

Returns the value of attribute color


3
4
5
# File 'lib/psd/slice.rb', line 3

def color
  @color
end

#group_idObject (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_alignmentObject (readonly)

Returns the value of attribute horizontal_alignment


3
4
5
# File 'lib/psd/slice.rb', line 3

def horizontal_alignment
  @horizontal_alignment
end

#idObject (readonly)

Returns the value of attribute id


3
4
5
# File 'lib/psd/slice.rb', line 3

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message


3
4
5
# File 'lib/psd/slice.rb', line 3

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/psd/slice.rb', line 3

def name
  @name
end

#originObject (readonly)

Returns the value of attribute origin


3
4
5
# File 'lib/psd/slice.rb', line 3

def origin
  @origin
end

#outsetObject (readonly)

Returns the value of attribute outset


3
4
5
# File 'lib/psd/slice.rb', line 3

def outset
  @outset
end

#targetObject (readonly)

Returns the value of attribute target


3
4
5
# File 'lib/psd/slice.rb', line 3

def target
  @target
end

#typeObject (readonly)

Returns the value of attribute type


3
4
5
# File 'lib/psd/slice.rb', line 3

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url


3
4
5
# File 'lib/psd/slice.rb', line 3

def url
  @url
end

#vertical_alignmentObject (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_layerObject


28
29
30
# File 'lib/psd/slice.rb', line 28

def associated_layer
  @psd.tree.find_by_id(associated_layer_id)
end

#heightObject


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_hashObject


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_pngObject


32
33
34
# File 'lib/psd/slice.rb', line 32

def to_png
  @png ||= @psd.image.to_png.crop(left, top, width, height)
end

#widthObject


20
21
22
# File 'lib/psd/slice.rb', line 20

def width
  right - left
end