Class: Sevgi::Graphics::Margin
- Inherits:
-
Data
- Object
- Data
- Sevgi::Graphics::Margin
- Includes:
- Comparable
- Defined in:
- lib/sevgi/graphics/auxilary/margin.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #change(h, v) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
- #htotal ⇒ Object
-
#initialize(top: nil, right: nil, bottom: nil, left: nil) ⇒ Margin
constructor
A new instance of Margin.
- #vtotal ⇒ Object
Constructor Details
#initialize(top: nil, right: nil, bottom: nil, left: nil) ⇒ Margin
Returns a new instance of Margin.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 8 def initialize(top: nil, right: nil, bottom: nil, left: nil) case [top, right, bottom, left] in [Numeric, Numeric, Numeric, Numeric] nil in [Numeric, Numeric, Numeric, NilClass] left = right in [Numeric, Numeric, NilClass, NilClass] bottom, left = top, right in [Numeric, NilClass, NilClass, NilClass] bottom, left, right = top, top, top in [NilClass, NilClass, NilClass, NilClass] top, bottom, left, right = 0, 0, 0, 0 end super(top: Float(top), right: Float(right), bottom: Float(bottom), left: Float(left)) end |
Instance Attribute Details
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom
5 6 7 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5 def bottom @bottom end |
#left ⇒ Object (readonly)
Returns the value of attribute left
5 6 7 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right
5 6 7 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5 def right @right end |
#top ⇒ Object (readonly)
Returns the value of attribute top
5 6 7 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5 def top @top end |
Class Method Details
.margin(array) ⇒ Object
40 41 42 43 44 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 40 def self.margin(array) self[ *(array = Array(array)[0...(size = Margin.members.size)]).fill(nil, array.size, size - array.size) ] end |
.zero ⇒ Object
46 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 46 def self.zero = (@zero ||= self[0.0, 0.0, 0.0, 0.0]) |
Instance Method Details
#<=>(other) ⇒ Object
25 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 25 def <=>(other) = deconstruct <=> other.deconstruct |
#change(h, v) ⇒ Object
27 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 27 def change(h, v) = self.class[top + v, right + h, bottom + v, left + h] |
#eql?(other) ⇒ Boolean Also known as: ==
29 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 29 def eql?(other) = self.class == other.class && deconstruct == other.deconstruct |
#hash ⇒ Object
31 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 31 def hash = [self.class, *deconstruct].hash |
#htotal ⇒ Object
33 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 33 def htotal = left + right |
#vtotal ⇒ Object
35 |
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 35 def vtotal = top + bottom |