Class: Vedeu::PositionValidator
- Inherits:
-
Object
- Object
- Vedeu::PositionValidator
- 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
-
#interface ⇒ Object
readonly
private
Returns the value of attribute interface.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
-
#border_validation ⇒ PositionValidator
private
Validate the x and y coordinates are within the dimensions of an interface with a border.
- #initialize(interface, x, y) ⇒ PositionValidator constructor
-
#interface_validation ⇒ PositionValidator
private
Validate the x and y coordinates are within the dimensions of the interface.
-
#terminal_validation ⇒ PositionValidator
private
Validate the x and y coordinates are within the dimensions of the terminal.
- #validate ⇒ PositionValidator
Constructor Details
#initialize(interface, x, y) ⇒ PositionValidator
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
#interface ⇒ Object (readonly, private)
Returns the value of attribute interface.
66 67 68 |
# File 'lib/vedeu/geometry/position_validator.rb', line 66 def interface @interface end |
#x ⇒ Object
Returns the value of attribute x.
35 36 37 |
# File 'lib/vedeu/geometry/position_validator.rb', line 35 def x @x end |
#y ⇒ Object
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
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_validation ⇒ PositionValidator (private)
Validate the x and y coordinates are within the dimensions of an interface with a border.
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_validation ⇒ PositionValidator (private)
Validate the x and y coordinates are within the dimensions of the interface.
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_validation ⇒ PositionValidator (private)
Validate the x and y coordinates are within the dimensions of the terminal.
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 |
#validate ⇒ PositionValidator
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 |