Class: JsonCanvas::GenericNode

Inherits:
Object
  • Object
show all
Defined in:
lib/json_canvas/node.rb

Direct Known Subclasses

FileNode, GroupNode, LinkNode, TextNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ GenericNode

Returns a new instance of GenericNode.



9
10
11
12
13
14
15
16
# File 'lib/json_canvas/node.rb', line 9

def initialize(**kwargs)
  @id = kwargs[:id] || SecureRandom.uuid.delete("-")[0...16]
  @x = kwargs[:x] || 0
  @y = kwargs[:y] || 0
  @width = kwargs[:width] || default_width
  @height = kwargs[:height] || default_height
  @color = kwargs[:color] # Optional

end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def color
  @color
end

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def height
  @height
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def id
  @id
end

#widthObject

Returns the value of attribute width.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def width
  @width
end

#xObject

Returns the value of attribute x.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def x
  @x
end

#yObject

Returns the value of attribute y.



7
8
9
# File 'lib/json_canvas/node.rb', line 7

def y
  @y
end

Instance Method Details

#default_heightObject



20
# File 'lib/json_canvas/node.rb', line 20

def default_height = is_a?(TextNode) ? 60 : 400

#default_widthObject



18
# File 'lib/json_canvas/node.rb', line 18

def default_width = is_a?(TextNode) ? 250 : 400

#to_hash_common(type) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/json_canvas/node.rb', line 22

def to_hash_common(type)
  h = {
    "id" => id,
    "x" => x,
    "y" => y,
    "width" => width,
    "height" => height
  }
  h["color"] = color if color
  h["type"] = type
  h
end