Class: Vedeu::Point Private
- Inherits:
-
Object
- Object
- Vedeu::Point
- 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
- #value ⇒ Fixnum readonly private
Class Method Summary collapse
- .coerce(value: nil, min: 1, max: Float::INFINITY) ⇒ Vedeu::Point private
- .valid?(value: nil, min: 1, max: Float::INFINITY) ⇒ Boolean, Vedeu::Point private
Instance Method Summary collapse
- #coerce ⇒ Vedeu::Point private
- #initialize(value: nil, min: 1, max: Float::INFINITY) ⇒ Vedeu::Point constructor private
- #max ⇒ Fixnum private private
- #min ⇒ Fixnum private private
- #valid? ⇒ Boolean private
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.
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
#value ⇒ Fixnum (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.
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.
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.
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
#coerce ⇒ 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.
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 |
#max ⇒ Fixnum (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.
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 |
#min ⇒ Fixnum (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.
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.
64 65 66 |
# File 'lib/vedeu/support/point.rb', line 64 def valid? numeric?(value) && value >= min && value <= max end |