Class: Vedeu::Point Private

Inherits:
Object
  • Object
show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value: nil, min: 1, max: nil) ⇒ 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) (defaults to: nil)


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

def initialize(value: nil, min: 1, max: nil)
  @min   = min
  @max   = max
  @value = value
end

Class Method Details

.coerce(value: nil, min: 1, max: nil) ⇒ 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) (defaults to: nil)

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.



15
16
17
# File 'lib/vedeu/support/point.rb', line 15

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

.valid?(value: nil, min: 1, max: nil) ⇒ 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) (defaults to: nil)

Returns:



21
22
23
# File 'lib/vedeu/support/point.rb', line 21

def self.valid?(value: nil, min: 1, max: nil)
  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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vedeu/support/point.rb', line 37

def coerce
  fail 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.



75
76
77
78
79
# File 'lib/vedeu/support/point.rb', line 75

def max
  return @max if @max.is_a?(Fixnum)

  fail Vedeu::Error::InvalidSyntax, "Expecting 'max' to be a Fixnum."
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.



67
68
69
70
71
# File 'lib/vedeu/support/point.rb', line 67

def min
  return @min if @min.is_a?(Fixnum)

  fail 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:



54
55
56
# File 'lib/vedeu/support/point.rb', line 54

def valid?
  @value.is_a?(Fixnum) && @value >= min && @value <= max
end

#valueFixnum

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)


59
60
61
# File 'lib/vedeu/support/point.rb', line 59

def value
  @value ||= min
end