module CartoJson class Circle < Point type :circle attr_accessor :radius def radius=(r) r = r.to_f # raise InvalidRadiusError, 'radius must be a number' unless (r.is_a?(Integer) || r.is_a?(Float)) raise InvalidRadiusError, 'radius cannot be negative' if r < 0 raise InvalidRadiusError, 'radius cannot be blank' if r.nil? raise InvalidRadiusError, 'radius cannot be zero' if r == 0 @radius = r end def to_wkt raise NotImplementedError, 'WKT does not support circles directly, conversion to polygon is required' end def to_point Point.new LAT => send(LAT), LNG => send(LNG) end def to_hash {:type => self.class.type, LAT => send(LAT), LNG => send(LNG), :radius => radius } end end end