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 35

#bottom=(value) ⇒ Integer

Set the bottom attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

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

#heightInteger

Get the total height of the attributes.

Returns:

  • (Integer)


77
78
79
# File 'lib/cura/attributes/has_side_attributes.rb', line 77

def height
  @top + @bottom
end

#initialize(attributes = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cura/attributes/has_side_attributes.rb', line 61

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 48

#left=(value) ⇒ Integer

Set the left attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

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

#rightInteger

Get the right attribute.

Returns:

  • (Integer)


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

#right=(value) ⇒ Integer

Set the right attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

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

#topInteger

Get the top attribute.

Returns:

  • (Integer)


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

#top=(value) ⇒ Integer

Set the top attribute.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

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

#widthInteger

Get the total width of the attributes.

Returns:

  • (Integer)


84
85
86
# File 'lib/cura/attributes/has_side_attributes.rb', line 84

def width
  @left + @right
end