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 quad.set(array) -> quad quad.set(hash) -> quad quad.set(quad) -> 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
quad.set(array) -> quad
quad.set(hash) -> quad
quad.set(quad) -> quad
Sets all values of the quad and returns it.
-
If a single value is provided that is neither a Quad nor an array nor a hash, 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.
-
-
If a hash is provided, the keys
:top
,:bottom
,:left
and:right
are used to set the respective value. All unspecified keys that have not been set before are set to 0.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/hexapdf/layout/style.rb', line 177 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] when Hash @top = obj[:top] || @top || 0 @bottom = obj[:bottom] || @bottom || 0 @left = obj[:left] || @left || 0 @right = obj[:right] || @right || 0 else @top = @bottom = @left = @right = obj end self end |
#simple? ⇒ Boolean
Returns true
if the quad effectively contains only one value.
201 202 203 |
# File 'lib/hexapdf/layout/style.rb', line 201 def simple? @top == @bottom && @top == @left && @top == @right end |