Class: Layouter::Leaf::Spacer

Inherits:
Base show all
Defined in:
lib/layouter/leaf/spacer.rb

Constant Summary

Constants inherited from Base

Base::EPS, Base::INF

Instance Attribute Summary collapse

Attributes inherited from Base

#importance

Attributes inherited from Element

#calculated_height, #calculated_width

Instance Method Summary collapse

Methods inherited from Base

#layout

Methods inherited from Element

#layout?

Constructor Details

#initialize(weight: 1) ⇒ Spacer

Returns a new instance of Spacer.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/layouter/leaf/spacer.rb', line 7

def initialize(weight: 1)
  unless weight.is_a?(Numeric)
    raise(ArgumentError, "Weight must be a number")
  end
  raise(ArgumentError, "Weight must more than 1") if weight < 1
  super(importance: EPS * weight)
  @min_width = @min_height = 0
  @max_width = @max_height = INF
end

Instance Attribute Details

#max_heightObject

Returns the value of attribute max_height.



5
6
7
# File 'lib/layouter/leaf/spacer.rb', line 5

def max_height
  @max_height
end

#max_widthObject

Returns the value of attribute max_width.



5
6
7
# File 'lib/layouter/leaf/spacer.rb', line 5

def max_width
  @max_width
end

#min_heightObject

Returns the value of attribute min_height.



5
6
7
# File 'lib/layouter/leaf/spacer.rb', line 5

def min_height
  @min_height
end

#min_widthObject

Returns the value of attribute min_width.



5
6
7
# File 'lib/layouter/leaf/spacer.rb', line 5

def min_width
  @min_width
end

Instance Method Details

#renderObject



17
18
19
20
# File 'lib/layouter/leaf/spacer.rb', line 17

def render
  layout!
  ([" " * @calculated_width] * @calculated_height).join("\n")
end