module Hexagonly::Point::Methods
Adds Point
methods to an object. Any Point
bears x and y coordinates, returned by the x and y methods. You can either override these methods to output your desired coordinates or you can map coordinate readers to different method names by using the x_y_coord_methods, x_coord_method or y_coord_method methods.
@example
class MyPoint include Hexagonly::Point::Methods # The x coordinate will be read from #a and the y coordinate will be read from #b x_y_coord_methods :a, :b attr_accessor :a, :b def initialize(a, b); @a, @b = a, b; end end p = MyPoint.new(1, 2) p.x_coord # => 1 p.y_coord # => 2
Attributes
geo_properties[RW]
Enable implicit splat. def to_ary
[x_coord, y_coord]
end
geo_style[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/hexagonly/point.rb, line 29 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
<=>(another_point)
click to toggle source
# File lib/hexagonly/point.rb, line 75 def <=>(another_point) if x_coord == another_point.x_coord && y_coord == another_point.y_coord 0 elsif x_coord > another_point.x_coord 1 else -1 end end
set_coords(x, y)
click to toggle source
Sets the coordinates for the current Point
.
@param x [Float] @param y [Float]
# File lib/hexagonly/point.rb, line 70 def set_coords(x, y) self.x_coord = x self.y_coord = y end
to_geojson()
click to toggle source
# File lib/hexagonly/point.rb, line 92 def to_geojson { :type => "Feature", :geometry => { :type => "Point", :coordinates => [x_coord, y_coord] }, :style => geo_style, :properties => geo_properties } end
x_coord()
click to toggle source
# File lib/hexagonly/point.rb, line 50 def x_coord send(self.class.x_coord_method_name || 'x') end
x_coord=(value)
click to toggle source
# File lib/hexagonly/point.rb, line 54 def x_coord=(value) send("#{self.class.x_coord_method_name || 'x'}=", value) end
y_coord()
click to toggle source
# File lib/hexagonly/point.rb, line 58 def y_coord send(self.class.y_coord_method_name || 'y') end
y_coord=(value)
click to toggle source
# File lib/hexagonly/point.rb, line 62 def y_coord=(value) send("#{self.class.y_coord_method_name || 'y'}=", value) end