Class: HexaPDF::Layout::Style::Quad
- Inherits:
-
Object
- Object
- HexaPDF::Layout::Style::Quad
- Defined in:
- lib/hexapdf/layout/style.rb
Overview
A Quad holds four values and allows them to be accessed by the names top, right, bottom and left. Quads are normally used for holding values pertaining to boxes, like margins, paddings or borders.
Instance Attribute Summary collapse
-
#bottom ⇒ Object
The value for bottom.
-
#left ⇒ Object
The value for left.
-
#right ⇒ Object
The value for right.
-
#top ⇒ Object
The value for top.
Instance Method Summary collapse
-
#initialize(obj) ⇒ Quad
constructor
Creates a new Quad object.
-
#set(obj) ⇒ Object
:call-seq: quad.set(value) quad.set(array) quad.set(quad).
-
#simple? ⇒ Boolean
Returns
true
if the quad effectively contains only one value.
Constructor Details
#initialize(obj) ⇒ Quad
Creates a new Quad object. See #set for more information.
142 143 144 |
# File 'lib/hexapdf/layout/style.rb', line 142 def initialize(obj) set(obj) end |
Instance Attribute Details
#bottom ⇒ Object
The value for bottom.
133 134 135 |
# File 'lib/hexapdf/layout/style.rb', line 133 def bottom @bottom end |
#left ⇒ Object
The value for left.
136 137 138 |
# File 'lib/hexapdf/layout/style.rb', line 136 def left @left end |
#right ⇒ Object
The value for right.
139 140 141 |
# File 'lib/hexapdf/layout/style.rb', line 139 def right @right end |
#top ⇒ Object
The value for top.
130 131 132 |
# File 'lib/hexapdf/layout/style.rb', line 130 def top @top end |
Instance Method Details
#set(obj) ⇒ Object
:call-seq:
quad.set(value)
quad.set(array)
quad.set(quad)
Sets all values of the quad.
-
If a single value is provided that is neither a Quad nor an array, it is handled as if an array with one value was given.
-
If a Quad is provided, its values are used.
-
If an array is provided, it depends on the number of elemens in it:
-
One value: All attributes are set to the same value.
-
Two values: Top and bottom are set to the first value, left and right to the second value.
-
Three values: Top is set to the first, left and right to the second, and bottom to the third value.
-
Four or more values: Top is set to the first, right to the second, bottom to the third and left to the fourth value.
-
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/hexapdf/layout/style.rb', line 167 def set(obj) case obj when Quad @top = obj.top @bottom = obj.bottom @left = obj.left @right = obj.right when Array @top = obj[0] @bottom = obj[2] || obj[0] @left = obj[3] || obj[1] || obj[0] @right = obj[1] || obj[0] else @top = @bottom = @left = @right = obj end end |
#simple? ⇒ Boolean
Returns true
if the quad effectively contains only one value.
185 186 187 |
# File 'lib/hexapdf/layout/style.rb', line 185 def simple? @top == @bottom && @top == @left && @top == @right end |