Module: Cura::Attributes::HasSideAttributes

Includes:
HasAttributes
Included in:
Borders, Margins, Padding
Defined in:
lib/cura/attributes/has_side_attributes.rb

Overview

Adds the ‘top`, `right`, `bottom`, `left`, `width`, and `height` attributes to objects.

Instance Method Summary collapse

Methods included from HasAttributes

included, #update_attributes

Instance Method Details

#bottomInteger

Get the bottom attribute.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_side_attributes.rb', line 39

#bottom=(value) ⇒ Integer

Set the bottom attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


50
# File 'lib/cura/attributes/has_side_attributes.rb', line 50

attribute(:bottom) { |value| validate_size_attribute(value) }

#heightInteger

Get the total height of the attributes.

Returns:

  • (Integer)


81
82
83
# File 'lib/cura/attributes/has_side_attributes.rb', line 81

def height
  @top + @bottom
end

#initialize(attributes = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cura/attributes/has_side_attributes.rb', line 65

def initialize(attributes={})
  @top = 0 unless instance_variable_defined?(:@top)
  @right = 0 unless instance_variable_defined?(:@right)
  @bottom = 0 unless instance_variable_defined?(:@bottom)
  @left = 0 unless instance_variable_defined?(:@left)
  
  unless attributes.respond_to?(:to_hash) || attributes.respond_to?(:to_h)
    attributes = { top: attributes, right: attributes, bottom: attributes, left: attributes } # Set all side attributes to the argument given
  end
  
  super
end

#leftInteger

Get the left attribute.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_side_attributes.rb', line 52

#left=(value) ⇒ Integer

Set the left attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


63
# File 'lib/cura/attributes/has_side_attributes.rb', line 63

attribute(:left) { |value| validate_size_attribute(value) }

#rightInteger

Get the right attribute.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_side_attributes.rb', line 26

#right=(value) ⇒ Integer

Set the right attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


37
# File 'lib/cura/attributes/has_side_attributes.rb', line 37

attribute(:right) { |value| validate_size_attribute(value) }

#topInteger

Get the top attribute.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_side_attributes.rb', line 13

#top=(value) ⇒ Integer

Set the top attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


24
# File 'lib/cura/attributes/has_side_attributes.rb', line 24

attribute(:top) { |value| validate_size_attribute(value) }

#widthInteger

Get the total width of the attributes.

Returns:

  • (Integer)


88
89
90
# File 'lib/cura/attributes/has_side_attributes.rb', line 88

def width
  @left + @right
end