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’s geometry (with or without a border).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, x, y) ⇒ PositionValidator

Returns a new instance of Vedeu::PositionValidator.



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

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

Instance Attribute Details

#nameString (readonly, protected)



57
58
59
# File 'lib/vedeu/geometry/position_validator.rb', line 57

def name
  @name
end

#xFixnum



17
18
19
# File 'lib/vedeu/geometry/position_validator.rb', line 17

def x
  @x
end

#yFixnum



21
22
23
# File 'lib/vedeu/geometry/position_validator.rb', line 21

def y
  @y
end

Class Method Details

.validate(name, x, y) ⇒ Object



24
25
26
# File 'lib/vedeu/geometry/position_validator.rb', line 24

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

Instance Method Details

#borderObject (private)



62
63
64
# File 'lib/vedeu/geometry/position_validator.rb', line 62

def border
  @border ||= Vedeu.borders.by_name(name)
end

#validatePositionValidator

Ensures the coordinates provided are within the terminal, interface and if applicable, bordered interface area.



44
45
46
47
48
49
50
51
# File 'lib/vedeu/geometry/position_validator.rb', line 44

def validate
  @x = bx  if x < bx
  @x = bxn if x > bxn
  @y = by  if y < by
  @y = byn if y > byn

  self
end