Class: CartoJson::LineString

Inherits:
Object
  • Object
show all
Includes:
Shape
Defined in:
lib/carto_json/line_string.rb

Direct Known Subclasses

Polygon

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shape

included, #to_json, #to_pretty_json, #to_s, #type

Constructor Details

#initialize(input) ⇒ LineString

Returns a new instance of LineString.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/carto_json/line_string.rb', line 8

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

Instance Attribute Details

#pointsObject

Returns the value of attribute points.



6
7
8
# File 'lib/carto_json/line_string.rb', line 6

def points
  @points
end

Instance Method Details

#to_hashObject



22
23
24
25
# File 'lib/carto_json/line_string.rb', line 22

def to_hash
  {:type   => self.class.type,
   :points => points.collect {|p| p.to_hash_for_array}}
end

#to_wktObject



27
28
29
# File 'lib/carto_json/line_string.rb', line 27

def to_wkt
  "#{type.to_s.upcase} (#{@points.dup.collect {|p| "#{p.send(LNG)} #{p.send(LAT)}"}.join(', ')})"
end