Class: Slideck::Margin Private
- Inherits:
-
Object
- Object
- Slideck::Margin
- Defined in:
- lib/slideck/margin.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for accessing margin configuration
Instance Attribute Summary collapse
-
#bottom ⇒ Integer
readonly
The bottom margin.
-
#left ⇒ Integer
readonly
The left margin.
-
#right ⇒ Integer
readonly
The right margin.
-
#top ⇒ Integer
readonly
The top margin.
Class Method Summary collapse
-
.[](*values) ⇒ Slideck::Margin
Create a Margin instance with an array-like initialiser.
-
.from(value) ⇒ Slideck::Margin
Create a Margin instance from a value.
-
.from_array(value) ⇒ Slideck::Margin
Create a Margin instance from an array.
-
.from_hash(value) ⇒ Slideck::Margin
Create a Margin instance from a hash.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Determine equivalence with another object.
-
#eql?(other) ⇒ Boolean
Determine for equality with another object.
-
#hash ⇒ Integer
Generate hash value of this margin.
-
#initialize(top, right, bottom, left) ⇒ Margin
constructor
private
Create a Margin instance.
-
#to_a ⇒ Array<Integer, Integer, Integer, Integer>
An array representation of all margin sides.
Constructor Details
#initialize(top, right, bottom, left) ⇒ Margin
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a Margin instance
253 254 255 256 257 258 259 260 |
# File 'lib/slideck/margin.rb', line 253 def initialize(top, right, bottom, left) @top = validate_margin_side(:top, top) @right = validate_margin_side(:right, right) @bottom = validate_margin_side(:bottom, bottom) @left = validate_margin_side(:left, left) freeze end |
Instance Attribute Details
#bottom ⇒ Integer (readonly)
The bottom margin
209 210 211 |
# File 'lib/slideck/margin.rb', line 209 def bottom @bottom end |
#left ⇒ Integer (readonly)
The left margin
219 220 221 |
# File 'lib/slideck/margin.rb', line 219 def left @left end |
#right ⇒ Integer (readonly)
The right margin
229 230 231 |
# File 'lib/slideck/margin.rb', line 229 def right @right end |
#top ⇒ Integer (readonly)
The top margin
239 240 241 |
# File 'lib/slideck/margin.rb', line 239 def top @top end |
Class Method Details
.[](*values) ⇒ Slideck::Margin
Create a Margin instance with an array-like initialiser
78 79 80 |
# File 'lib/slideck/margin.rb', line 78 def self.[](*values) from_array(values) end |
.from(value) ⇒ Slideck::Margin
Create a Margin instance from a value
54 55 56 57 58 59 60 61 62 |
# File 'lib/slideck/margin.rb', line 54 def self.from(value) if value.is_a?(Hash) from_hash(value) elsif (converted = convert_to_array(value)) from_array(converted) else raise_invalid_margin_error(value) end end |
.from_array(value) ⇒ Slideck::Margin
Create a Margin instance from an array
95 96 97 98 99 100 101 102 103 |
# File 'lib/slideck/margin.rb', line 95 def self.from_array(value) case value.size when 1 then new(*(value * 4)) when 2 then new(*(value * 2)) when 3 then new(*value, value[1]) when 4 then new(*value) else raise_invalid_margin_as_array_error(value) end end |
.from_hash(value) ⇒ Slideck::Margin
Create a Margin instance from a hash
118 119 120 121 122 123 124 |
# File 'lib/slideck/margin.rb', line 118 def self.from_hash(value) unless (invalid = (value.keys - SIDE_NAMES)).empty? raise_invalid_margin_as_hash_error(invalid) end new(*value.values_at(*SIDE_NAMES).map { |val| val.nil? ? 0 : val }) end |
Instance Method Details
#==(other) ⇒ Boolean
Determine equivalence with another object
275 276 277 278 279 |
# File 'lib/slideck/margin.rb', line 275 def ==(other) other.is_a?(self.class) && top == other.top && right == other.right && bottom == other.bottom && left == other.left end |
#eql?(other) ⇒ Boolean
Determine for equality with another object
293 294 295 296 297 |
# File 'lib/slideck/margin.rb', line 293 def eql?(other) instance_of?(other.class) && top.eql?(other.top) && right.eql?(other.right) && bottom.eql?(other.bottom) && left.eql?(other.left) end |
#hash ⇒ Integer
Generate hash value of this margin
307 308 309 |
# File 'lib/slideck/margin.rb', line 307 def hash [self.class, top, right, bottom, left].hash end |
#to_a ⇒ Array<Integer, Integer, Integer, Integer>
An array representation of all margin sides
320 321 322 |
# File 'lib/slideck/margin.rb', line 320 def to_a [top, right, bottom, left] end |