Class: Vedeu::Point Private

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/support/point.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A Vedeu::Point represents part of a coordinate within the 2D space of a terminal. This class is specifically used to coerce a coordinate to be within boundaries. The min and max arguments are used to define this boundary.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(value: nil, min: 1, max: Float::INFINITY) ⇒ Vedeu::Point

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Fixnum|NilClass) (defaults to: nil)
  • min (Fixnum) (defaults to: 1)
  • max (Fixnum|Float::INFINITY) (defaults to: Float::INFINITY)


37
38
39
40
41
42
43
# File 'lib/vedeu/support/point.rb', line 37

def initialize(value: nil, min: 1, max: Float::INFINITY)
  @min   = min
  @max   = max
  @value = value || @min

  freeze
end

Instance Attribute Details

#valueFixnum (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


18
19
20
# File 'lib/vedeu/support/point.rb', line 18

def value
  @value
end

Class Method Details

.coerce(value: nil, min: 1, max: Float::INFINITY) ⇒ Vedeu::Point

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Fixnum|NilClass) (defaults to: nil)
  • min (Fixnum) (defaults to: 1)
  • max (Fixnum|Float::INFINITY) (defaults to: Float::INFINITY)

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



23
24
25
# File 'lib/vedeu/support/point.rb', line 23

def self.coerce(value: nil, min: 1, max: Float::INFINITY)
  new(value: value, min: min, max: max).coerce
end

.valid?(value: nil, min: 1, max: Float::INFINITY) ⇒ Boolean, Vedeu::Point

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Fixnum|NilClass) (defaults to: nil)
  • min (Fixnum) (defaults to: 1)
  • max (Fixnum|Float::INFINITY) (defaults to: Float::INFINITY)

Returns:



29
30
31
# File 'lib/vedeu/support/point.rb', line 29

def self.valid?(value: nil, min: 1, max: Float::INFINITY)
  new(value: value, min: min, max: max).valid?
end

Instance Method Details

#coerceVedeu::Point

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vedeu/support/point.rb', line 47

def coerce
  raise Vedeu::Error::InvalidSyntax,
        "Expecting 'min' to be less than 'max'." if min > max

  if value < min
    Vedeu::Point.coerce(value: min, min: min, max: max)

  elsif value > max
    Vedeu::Point.coerce(value: max, min: min, max: max)

  else
    self

  end
end

#maxFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



81
82
83
84
85
86
# File 'lib/vedeu/support/point.rb', line 81

def max
  return @max if numeric?(@max)

  raise Vedeu::Error::InvalidSyntax,
        "Expecting 'max' to be a Fixnum or Float::INFINITY."
end

#minFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



72
73
74
75
76
77
# File 'lib/vedeu/support/point.rb', line 72

def min
  return @min if numeric?(@min)

  raise Vedeu::Error::InvalidSyntax,
        "Expecting 'min' to be a Fixnum."
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



64
65
66
# File 'lib/vedeu/support/point.rb', line 64

def valid?
  numeric?(value) && value >= min && value <= max
end