Class: JsonCanvas::GenericNode
- Inherits:
-
Object
- Object
- JsonCanvas::GenericNode
- Defined in:
- lib/json_canvas/node.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #default_height ⇒ Object
- #default_width ⇒ Object
-
#initialize(**kwargs) ⇒ GenericNode
constructor
A new instance of GenericNode.
- #to_hash_common(type) ⇒ Object
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
#color ⇒ Object
Returns the value of attribute color.
7 8 9 |
# File 'lib/json_canvas/node.rb', line 7 def color @color end |
#height ⇒ Object
Returns the value of attribute height.
7 8 9 |
# File 'lib/json_canvas/node.rb', line 7 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/json_canvas/node.rb', line 7 def id @id end |
#width ⇒ Object
Returns the value of attribute width.
7 8 9 |
# File 'lib/json_canvas/node.rb', line 7 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'lib/json_canvas/node.rb', line 7 def x @x end |
#y ⇒ Object
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_height ⇒ Object
20 |
# File 'lib/json_canvas/node.rb', line 20 def default_height = is_a?(TextNode) ? 60 : 400 |
#default_width ⇒ Object
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 |