lib/vedeu/geometries/position.rb in vedeu-0.6.70 vs lib/vedeu/geometries/position.rb in vedeu-0.6.71
- old
+ new
@@ -20,23 +20,27 @@
alias_method :last, :x
# Convenience constructor for Vedeu::Geometries::Position.
#
# @param (see #initialize)
- def self.[](y, x)
+ def self.[](y = 1, x = 1)
new(y, x)
end
- # @param value [Array<Fixnum>|Vedeu::Geometries::Position]
+ # @param value [Array<Fixnum>|Fixnum|Hash|
+ # Vedeu::Geometries::Position]
# @return [Vedeu::Geometries::Position]
def self.coerce(value)
if value.is_a?(self)
value
elsif value.is_a?(Array)
new(*value)
+ elsif value.is_a?(Fixnum)
+ new(value, 1)
+
elsif value.is_a?(Hash)
new(value.fetch(:y, 1), value.fetch(:x, 1))
end
end
@@ -90,12 +94,17 @@
# @return [Array<Fixnum>]
def to_a
[y, x]
end
- # @return [Vedeu::Geometries::Position]
- def to_position
- self
+ # Return the position as a Hash.
+ #
+ # @return [Hash<Symbol => Fixnum|NilClass>]
+ def to_h
+ {
+ y: y,
+ x: x,
+ }
end
# Return the escape sequence required to position the cursor at
# a particular point on the screen. When passed a block, will do
# the aforementioned, call the block and then reposition to this