Class: Vedeu::Coercers::Position Private
- Defined in:
- lib/vedeu/coercers/position.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.
Provides the mechanism to convert a value into a Geometries::Position.
Instance Attribute Summary
Attributes inherited from Coercer
Instance Method Summary collapse
- #coerce ⇒ NilClass|Vedeu::Geometries::Position private
- #klass ⇒ Class private private
- #tuple? ⇒ Boolean private private
Methods inherited from Coercer
#child_klass, coerce, #coerced?, #incoercible!, #initialize
Methods included from Vedeu::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
This class inherits a constructor from Vedeu::Coercers::Coercer
Instance Method Details
#coerce ⇒ NilClass|Vedeu::Geometries::Position
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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vedeu/coercers/position.rb', line 16 def coerce if value.nil? || coerced? value elsif tuple? klass.new(*value) elsif hash?(value) klass.new(value.fetch(:y, 1), value.fetch(:x, 1)) elsif numeric?(value) klass.new(value, 1) else incoercible! end end |
#klass ⇒ Class (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.
38 39 40 |
# File 'lib/vedeu/coercers/position.rb', line 38 def klass Vedeu::Geometries::Position end |
#tuple? ⇒ Boolean (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.
44 45 46 47 48 49 50 51 |
# File 'lib/vedeu/coercers/position.rb', line 44 def tuple? return false unless array?(value) return true if value.size == 2 raise Vedeu::Error::Fatal, "A '#{klass}' is made up of two elements. (Provided " \ "#{value.size}.)" end |