Class: PSD::PathRecord
- Inherits:
-
Object
- Object
- PSD::PathRecord
- Defined in:
- lib/psd/path_record.rb
Overview
Parses a vector path
Instance Attribute Summary collapse
-
#layer ⇒ Object
Returns the value of attribute layer.
Class Method Summary collapse
-
.read(layer) ⇒ Object
Facade to make it easier to parse the path record.
Instance Method Summary collapse
-
#initialize(file) ⇒ PathRecord
constructor
Reads the record type and begins parsing accordingly.
-
#is_bezier_point? ⇒ Boolean
Is this record a bezier point?.
-
#to_hash ⇒ Object
Exports the path record to an easier to work with hash.
Constructor Details
#initialize(file) ⇒ PathRecord
Reads the record type and begins parsing accordingly.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/psd/path_record.rb', line 14 def initialize(file) @file = file @record_type = @file.read_short case @record_type when 0, 3 then read_path_record when 1, 2, 4, 5 then read_bezier_point when 6 then read_path_fill_rule_record when 7 then read_clipboard_record when 8 then read_initial_fill else @file.seek(24, IO::SEEK_CUR) end end |
Instance Attribute Details
#layer ⇒ Object
Returns the value of attribute layer.
4 5 6 |
# File 'lib/psd/path_record.rb', line 4 def layer @layer end |
Class Method Details
.read(layer) ⇒ Object
Facade to make it easier to parse the path record.
7 8 9 10 11 |
# File 'lib/psd/path_record.rb', line 7 def self.read(layer) pr = PSD::PathRecord.new(layer.file) pr.layer = layer pr end |
Instance Method Details
#is_bezier_point? ⇒ Boolean
Is this record a bezier point?
73 74 75 |
# File 'lib/psd/path_record.rb', line 73 def is_bezier_point? [1,2,4,5].include? @record_type end |
#to_hash ⇒ Object
Exports the path record to an easier to work with hash.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/psd/path_record.rb', line 30 def to_hash case @record_type when 0, 3 { num_points: @num_points } when 1, 2, 4, 5 { linked: @linked, closed: [1, 2].include?(@record_type), preceding: { vert: @preceding_vert, horiz: @preceding_horiz }, anchor: { vert: @anchor_vert, horiz: @anchor_horiz }, leaving: { vert: @leaving_vert, horiz: @leaving_horiz } } when 7 { clipboard: { top: @clipboard_top, left: @clipboard_left, bottom: @clipboard_bottom, right: @clipboard_right, resolution: @clipboard_resolution } } when 8 { initial_fill: @initial_fill } else {} end.merge({ record_type: @record_type }) end |