Module: Cura::Attributes::HasDimensions

Includes:
HasAttributes
Included in:
Component::Base, Event::Resize, Window
Defined in:
lib/cura/attributes/has_dimensions.rb

Overview

Adds the ‘width` and `height` attributes.

Instance Method Summary collapse

Methods included from HasAttributes

included, #update_attributes

Instance Method Details

#heightInteger

Get the height dimension of this object.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_dimensions.rb', line 29

#height=(value) ⇒ Integer

Set the height dimension of this object.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


40
# File 'lib/cura/attributes/has_dimensions.rb', line 40

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

#initialize(attributes = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/cura/attributes/has_dimensions.rb', line 9

def initialize(attributes={})
  @width = :auto unless instance_variable_defined?(:@width)
  @height = :auto unless instance_variable_defined?(:@height)

  super
end

#resize(options) ⇒ Object

Set one or both of the dimensions of this object.

Parameters:

  • options (#to_h)

Options Hash (options):

  • :width (#to_i)
  • :height (#to_i)

Returns:

  • (Object)

    This object



47
48
49
50
51
52
53
54
# File 'lib/cura/attributes/has_dimensions.rb', line 47

def resize(options)
  options = options.to_h

  self.width = options[:width] if options.key?(:width)
  self.height = options[:height] if options.key?(:height)

  self
end

#widthInteger

Get the width dimension of this object.

Returns:

  • (Integer)


# File 'lib/cura/attributes/has_dimensions.rb', line 16

#width=(value) ⇒ Integer

Set the width dimension of this object.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


27
# File 'lib/cura/attributes/has_dimensions.rb', line 27

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