Class: Vedeu::PositionValidator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/geometry/position_validator.rb

Overview

Validates that the provided coordinates are within the terminal and interface (with or without a border).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface, x, y) ⇒ PositionValidator

Parameters:



49
50
51
52
53
# File 'lib/vedeu/geometry/position_validator.rb', line 49

def initialize(interface, x, y)
  @interface = interface
  @x         = x
  @y         = y
end

Instance Attribute Details

#interfaceObject (readonly, private)

Returns the value of attribute interface.



66
67
68
# File 'lib/vedeu/geometry/position_validator.rb', line 66

def interface
  @interface
end

#xObject

Returns the value of attribute x.



35
36
37
# File 'lib/vedeu/geometry/position_validator.rb', line 35

def x
  @x
end

#yObject

Returns the value of attribute y.



35
36
37
# File 'lib/vedeu/geometry/position_validator.rb', line 35

def y
  @y
end

Class Method Details

.validate(interface, x, y) ⇒ PositionValidator

Parameters:

Returns:



41
42
43
# File 'lib/vedeu/geometry/position_validator.rb', line 41

def self.validate(interface, x, y)
  new(interface, x, y).validate
end

Instance Method Details

#border_validationPositionValidator (private)

Validate the x and y coordinates are within the dimensions of an interface with a border.

Returns:



98
99
100
101
102
103
104
105
# File 'lib/vedeu/geometry/position_validator.rb', line 98

def border_validation
  @x = left + 1   if left?   && x < (left + 1)
  @x = right - 2  if right?  && x > (right - 1)
  @y = top + 1    if top?    && y < (top + 1)
  @y = bottom - 2 if bottom? && y > (bottom - 1)

  self
end

#interface_validationPositionValidator (private)

Validate the x and y coordinates are within the dimensions of the interface.

Returns:



85
86
87
88
89
90
91
92
# File 'lib/vedeu/geometry/position_validator.rb', line 85

def interface_validation
  @x = left   if x < left
  @x = right  if x > right
  @y = top    if y < top
  @y = bottom if y > bottom

  self
end

#terminal_validationPositionValidator (private)

Validate the x and y coordinates are within the dimensions of the terminal.

Returns:



72
73
74
75
76
77
78
79
# File 'lib/vedeu/geometry/position_validator.rb', line 72

def terminal_validation
  @x = tx  if x < tx
  @x = txn if x > txn
  @y = ty  if y < ty
  @y = tyn if y > tyn

  self
end

#validatePositionValidator

Returns:



56
57
58
59
60
61
62
# File 'lib/vedeu/geometry/position_validator.rb', line 56

def validate
  terminal_validation
  interface_validation
  border_validation if border?

  self
end