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.
148 149 150 |
# File 'lib/hexapdf/layout/style.rb', line 148 def initialize(obj) set(obj) end |
Instance Attribute Details
#bottom ⇒ Object
The value for bottom.
139 140 141 |
# File 'lib/hexapdf/layout/style.rb', line 139 def bottom @bottom end |
#left ⇒ Object
The value for left.
142 143 144 |
# File 'lib/hexapdf/layout/style.rb', line 142 def left @left end |
#right ⇒ Object
The value for right.
145 146 147 |
# File 'lib/hexapdf/layout/style.rb', line 145 def right @right end |
#top ⇒ Object
The value for top.
136 137 138 |
# File 'lib/hexapdf/layout/style.rb', line 136 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.
-
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/hexapdf/layout/style.rb', line 173 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.
191 192 193 |
# File 'lib/hexapdf/layout/style.rb', line 191 def simple? @top == @bottom && @top == @left && @top == @right end |