Class: Qippet::Boxes::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/qippet/boxes/box.rb

Overview

Abstract Class definiton for Box

Direct Known Subclasses

CodeBox, ContainerBox, TextBox

Constant Summary collapse

PADDING =
40
PADDING_X =
30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBox

Returns a new instance of Box.



14
15
16
# File 'lib/qippet/boxes/box.rb', line 14

def initialize
  self.class.setup_attributes
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



9
10
11
# File 'lib/qippet/boxes/box.rb', line 9

def image
  @image
end

#nodeObject (readonly)

Returns the value of attribute node.



9
10
11
# File 'lib/qippet/boxes/box.rb', line 9

def node
  @node
end

Class Method Details

.setup_attributesObject



35
36
37
38
39
# File 'lib/qippet/boxes/box.rb', line 35

def self.setup_attributes
  return unless const_defined? "ALLOWED_ATTRIBUTES"

  self::ALLOWED_ATTRIBUTES.each { |attr| attr_accessor attr }
end

Instance Method Details

#add_attributes(attributes_value) ⇒ Object



30
31
32
33
# File 'lib/qippet/boxes/box.rb', line 30

def add_attributes(attributes_value)
  allowed_attributes = attributes_value.filter { |key, _| self.class::ALLOWED_ATTRIBUTES.include?(key.to_sym) }
  allowed_attributes.each { |key, val| instance_variable_set "@#{key}", val }
end

#add_child(child) ⇒ Object



18
19
20
# File 'lib/qippet/boxes/box.rb', line 18

def add_child(child)
  children << child
end

#childrenObject



26
27
28
# File 'lib/qippet/boxes/box.rb', line 26

def children
  @children ||= []
end

#renderObject



22
23
24
# File 'lib/qippet/boxes/box.rb', line 22

def render
  construct_box_image
end