Sha256: 91e20e8e3713f774e6b78179fef8c9eeff8a228bc4843e1f1b861154aba57920
Contents?: true
Size: 824 Bytes
Versions: 3
Compression:
Stored size: 824 Bytes
Contents
module CartoJson class LineString include Shape type :linestring attr_accessor :points def initialize(input) super @points = [] input[:points].each do |p| if p.is_a?(Point) @points << p else @points << Point.new(LAT => p[LAT], LNG => p[LNG]) end end validate end def to_hash {:type => self.class.type, :points => points.collect {|p| p.to_hash_for_array}} end def to_wkt "#{type.to_s.upcase} (#{@points.dup.collect {|p| "#{p.send(LNG)} #{p.send(LAT)}"}.join(', ')})" end protected def validate if @points.length < 2 raise InsufficientPointsError, "a minimum of 2 points is required to make a linestring, you provided #{@points.length}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
carto_json-0.0.9 | lib/carto_json/line_string.rb |
carto_json-0.0.8 | lib/carto_json/line_string.rb |
carto_json-0.0.7 | lib/carto_json/line_string.rb |