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 33

#height=(value) ⇒ Integer

Set the height dimension of this object.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

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

#initialize(attributes = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/cura/attributes/has_dimensions.rb', line 13

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



51
52
53
54
55
56
57
58
# File 'lib/cura/attributes/has_dimensions.rb', line 51

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.

Parameters:

  • value (#to_i)

Returns:

  • (Integer)


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

#width=(value) ⇒ Integer

Set the width dimension of this object.

Returns:

  • (Integer)


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

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