Class: Cura::Offsets

Inherits:
Object
  • Object
show all
Includes:
Attributes::HasAttributes, Attributes::HasInitialize
Defined in:
lib/cura/offsets.rb

Overview

The offsets of a component’s drawing area.

Instance Method Summary collapse

Methods included from Attributes::HasAttributes

included, #update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Offsets

Returns a new instance of Offsets.

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/cura/offsets.rb', line 15

def initialize(attributes={})
  super
  
  raise ArgumentError, "component must be set" if @component.nil?
end

Instance Method Details

#bottomInteger

Get the bottom offset from the contents of a component from the bottom.

Returns:

  • (Integer)


50
51
52
# File 'lib/cura/offsets.rb', line 50

def bottom
  attribute_sum(:bottom)
end

#componentComponent

Get the component to calculate offsets for.

Returns:



# File 'lib/cura/offsets.rb', line 21

#component=(value) ⇒ Component

Set the component to calculate offsets for.

Parameters:

Returns:



31
# File 'lib/cura/offsets.rb', line 31

attribute(:component) { |value| validate_component(value) }

#heightInteger

Get the full height of offsets of a component.

Returns:

  • (Integer)


64
65
66
67
# File 'lib/cura/offsets.rb', line 64

def height
  # top + bottom
  attribute_sum(:height)
end

#leftInteger

Get the left offset from the contents of a component from the left.

Returns:

  • (Integer)


57
58
59
# File 'lib/cura/offsets.rb', line 57

def left
  attribute_sum(:left)
end

#rightInteger

Get the right offset from the contents of a component from the right.

Returns:

  • (Integer)


43
44
45
# File 'lib/cura/offsets.rb', line 43

def right
  attribute_sum(:right)
end

#topInteger

Get the top offset from the contents of a component from the top.

Returns:

  • (Integer)


36
37
38
# File 'lib/cura/offsets.rb', line 36

def top
  attribute_sum(:top)
end

#widthInteger

Get the full width of offsets of a component.

Returns:

  • (Integer)


72
73
74
75
# File 'lib/cura/offsets.rb', line 72

def width
  # left + right
  attribute_sum(:width)
end