Class: PSD::Node::Base
- Inherits:
-
Object
- Object
- PSD::Node::Base
- Extended by:
- Forwardable
- Includes:
- Enumerable, Ancestry, BuildPreview, LayerComps, Search
- Defined in:
- lib/psd/node.rb
Constant Summary collapse
- PROPERTIES =
Default properties that all nodes contain
[:name, :left, :right, :top, :bottom, :height, :width]
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#force_visible ⇒ Object
Returns the value of attribute force_visible.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#left_offset ⇒ Object
Returns the value of attribute left_offset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#top_offset ⇒ Object
Returns the value of attribute top_offset.
Instance Method Summary collapse
- #bottom ⇒ Object
- #clipping_mask ⇒ Object (also: #clipped_by)
- #debug_name ⇒ Object
- #group?(include_root = true) ⇒ Boolean
- #height ⇒ Object
- #hidden? ⇒ Boolean
-
#initialize(layer, parent = nil) ⇒ Base
constructor
A new instance of Base.
- #layer? ⇒ Boolean
- #left ⇒ Object
- #right ⇒ Object
- #to_hash ⇒ Object
- #top ⇒ Object
- #visible? ⇒ Boolean
- #width ⇒ Object
Methods included from BuildPreview
#renderer, #save_as_png, #to_png
Methods included from LayerComps
#filter_by_comp, #position_in_comp, #visible_in_comp?
Methods included from Search
#children_at_path, #find_by_id
Methods included from Ancestry
#ancestors, #childless?, #depth, #descendants, #has_children?, #has_siblings?, #method_missing, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree
Constructor Details
#initialize(layer, parent = nil) ⇒ Base
Returns a new instance of Base.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/psd/node.rb', line 29 def initialize(layer, parent = nil) @layer = layer @layer.node = self @parent = parent @children = [] @id = begin layer.layer_id.id rescue nil end @force_visible = nil @top = @layer.top.to_i @bottom = @layer.bottom.to_i @left = @layer.left.to_i @right = @layer.right.to_i @top_offset = 0 @left_offset = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PSD::Node::Ancestry
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
23 24 25 |
# File 'lib/psd/node.rb', line 23 def children @children end |
#force_visible ⇒ Object
Returns the value of attribute force_visible.
23 24 25 |
# File 'lib/psd/node.rb', line 23 def force_visible @force_visible end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/psd/node.rb', line 22 def id @id end |
#layer ⇒ Object
Returns the value of attribute layer.
23 24 25 |
# File 'lib/psd/node.rb', line 23 def layer @layer end |
#left_offset ⇒ Object
Returns the value of attribute left_offset.
23 24 25 |
# File 'lib/psd/node.rb', line 23 def left_offset @left_offset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/psd/node.rb', line 22 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
22 23 24 |
# File 'lib/psd/node.rb', line 22 def parent @parent end |
#top_offset ⇒ Object
Returns the value of attribute top_offset.
23 24 25 |
# File 'lib/psd/node.rb', line 23 def top_offset @top_offset end |
Instance Method Details
#bottom ⇒ Object
51 52 53 |
# File 'lib/psd/node.rb', line 51 def bottom @bottom + @top_offset end |
#clipping_mask ⇒ Object Also known as: clipped_by
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/psd/node.rb', line 80 def clipping_mask return nil unless @layer.clipped? @clipping_mask ||= ( mask_node = next_sibling while mask_node.clipped? mask_node = mask_node.next_sibling end mask_node ) end |
#debug_name ⇒ Object
102 103 104 |
# File 'lib/psd/node.rb', line 102 def debug_name root? ? ":root:" : name end |
#group?(include_root = true) ⇒ Boolean
98 99 100 |
# File 'lib/psd/node.rb', line 98 def group?(include_root = true) is_a?(PSD::Node::Group) || (include_root && is_a?(PSD::Node::Root)) end |
#height ⇒ Object
67 68 69 |
# File 'lib/psd/node.rb', line 67 def height bottom - top end |
#hidden? ⇒ Boolean
71 72 73 |
# File 'lib/psd/node.rb', line 71 def hidden? !visible? end |
#left ⇒ Object
55 56 57 |
# File 'lib/psd/node.rb', line 55 def left @left + @left_offset end |
#right ⇒ Object
59 60 61 |
# File 'lib/psd/node.rb', line 59 def right @right + @left_offset end |
#to_hash ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/psd/node.rb', line 106 def to_hash hash = { type: nil, visible: visible?, opacity: @layer.opacity / 255.0, blending_mode: @layer.blending_mode, layer_comps: {} } PROPERTIES.each do |p| hash[p] = self.send(p) end root.psd.layer_comps.each do |comp| hash[:layer_comps][comp[:name]] = { visible: visible_in_comp?(comp[:id]), position: position_in_comp(comp[:id]) } end hash end |
#top ⇒ Object
47 48 49 |
# File 'lib/psd/node.rb', line 47 def top @top + @top_offset end |
#visible? ⇒ Boolean
75 76 77 78 |
# File 'lib/psd/node.rb', line 75 def visible? return false if @layer.clipped? && !clipping_mask.visible? @force_visible.nil? ? @layer.visible? : @force_visible end |
#width ⇒ Object
63 64 65 |
# File 'lib/psd/node.rb', line 63 def width right - left end |