Sha256: f4e53535b0eba7736407b4d506fb32daccbbef2c6eb62cf00bec2311ab314828

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

module Vedeu

  # Validates that the provided coordinates are within the terminal and
  # interface's geometry (with or without a border).
  class PositionValidator

    extend Forwardable

    def_delegators :border,
                   :bx,
                   :bxn,
                   :by,
                   :byn

    # @!attribute [rw] x
    # @return [Fixnum]
    attr_accessor :x

    # @!attribute [rw] x
    # @return [Fixnum]
    attr_accessor :y

    # @param (see #initialize)
    def self.validate(name, x, y)
      new(name, x, y).validate
    end

    # Returns a new instance of Vedeu::PositionValidator.
    #
    # @param name [String]
    # @param x [Fixnum]
    # @param y [Fixnum]
    # @return [PositionValidator]
    def initialize(name, x, y)
      @name = name
      @x    = x
      @y    = y
    end

    # Ensures the coordinates provided are within the terminal, interface and
    # if applicable, bordered interface area.
    #
    # @return [PositionValidator]
    def validate
      @x = bx  if x < bx
      @x = bxn if x > bxn
      @y = by  if y < by
      @y = byn if y > byn

      self
    end

    protected

    # @!attribute [r] name
    # @return [String]
    attr_reader :name

    private

    # @return (see Vedeu::Borders#by_name)
    def border
      @border ||= Vedeu.borders.by_name(name)
    end

  end # PositionValidator

end # Vedeu

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.4.29 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.28 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.27 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.26 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.25 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.24 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.23 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.22 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.21 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.20 lib/vedeu/geometry/position_validator.rb
vedeu-0.4.19 lib/vedeu/geometry/position_validator.rb