class RGrid::Validator
Validates the RGrid::Grid
parameters to ensure sanity.
@api private
Attributes
x[R]
@!attribute [r] x @return [Fixnum]
x?[R]
@!attribute [r] x @return [Fixnum]
xn[R]
@!attribute [r] xn @return [Fixnum]
xn?[R]
@!attribute [r] xn @return [Fixnum]
y[R]
@!attribute [r] y @return [Fixnum]
y?[R]
@!attribute [r] y @return [Fixnum]
yn[R]
@!attribute [r] yn @return [Fixnum]
yn?[R]
@!attribute [r] yn @return [Fixnum]
Public Class Methods
new(x: nil, xn: nil, y: nil, yn: nil)
click to toggle source
@param x [Fixnum] @param xn [Fixnum] @param y [Fixnum] @param yn [Fixnum] @return [RGrid::Validator]
# File lib/rgrid/validator.rb, line 22 def initialize(x: nil, xn: nil, y: nil, yn: nil) @x = x @xn = xn @y = y @yn = yn end
valid?(x: nil, xn: nil, y: nil, yn: nil)
click to toggle source
@param (see initialize) @return (see valid?
)
# File lib/rgrid/validator.rb, line 13 def self.valid?(x: nil, xn: nil, y: nil, yn: nil) new(x: x, xn: xn, y: y, yn: yn).valid? end
Public Instance Methods
valid?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 30 def valid? return true if valid_height? && valid_width? raise RGrid::InvalidGrid, 'Grid cannot be created as parameters are invalid.' end
Private Instance Methods
columns?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 62 def columns? x? && !xn? end
height?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 67 def height? y? && yn? end
rows?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 72 def rows? y? && !yn? end
valid_height?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 77 def valid_height? if height? yn >= y elsif rows? y > 0 else false end end
valid_width?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 91 def valid_width? if width? xn >= x elsif columns? x > 0 else false end end
width?()
click to toggle source
@return [Boolean]
# File lib/rgrid/validator.rb, line 105 def width? x? && xn? end