Class: Sevgi::Graphics::Margin

Inherits:
Data
  • Object
show all
Includes:
Comparable
Defined in:
lib/sevgi/graphics/auxilary/margin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bottomObject (readonly)

Returns the value of attribute bottom

Returns:

  • (Object)

    the current value of bottom



5
6
7
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5

def bottom
  @bottom
end

#leftObject (readonly)

Returns the value of attribute left

Returns:

  • (Object)

    the current value of left



5
6
7
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right

Returns:

  • (Object)

    the current value of right



5
6
7
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 5

def right
  @right
end

#topObject (readonly)

Returns the value of attribute top

Returns:

  • (Object)

    the current value of 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

.zeroObject



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: ==

Returns:

  • (Boolean)


29
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 29

def eql?(other) = self.class == other.class && deconstruct == other.deconstruct

#hashObject



31
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 31

def hash = [self.class, *deconstruct].hash

#htotalObject



33
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 33

def htotal = left + right

#vtotalObject



35
# File 'lib/sevgi/graphics/auxilary/margin.rb', line 35

def vtotal = top + bottom