Module: CartoJson::Shape
- Included in:
- LineString, Point
- Defined in:
- lib/carto_json/shape.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(input = nil) ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_pretty_json ⇒ Object
- #to_s ⇒ Object
- #to_wkt ⇒ Object
- #type ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/carto_json/shape.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#initialize(input = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/carto_json/shape.rb', line 21 def initialize(input=nil) raise InputError, 'cannot create a shape with an array' if input.is_a?(Array) if input.respond_to?(:each) input.each do |k,v| next if k == :type raise InputError, "\"#{k}\" is not a valid property" unless respond_to? k send "#{k}=".to_sym, v end end end |
#to_hash ⇒ Object
33 34 35 |
# File 'lib/carto_json/shape.rb', line 33 def to_hash raise NotImplementedError, 'you need to provide the to_hash method' end |
#to_json ⇒ Object
37 38 39 |
# File 'lib/carto_json/shape.rb', line 37 def to_json MultiJson.encode to_hash end |
#to_pretty_json ⇒ Object
41 42 43 |
# File 'lib/carto_json/shape.rb', line 41 def to_pretty_json MultiJson.encode to_hash, :pretty => true end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/carto_json/shape.rb', line 49 def to_s to_json end |
#to_wkt ⇒ Object
53 54 55 |
# File 'lib/carto_json/shape.rb', line 53 def to_wkt "#{self.class.name.split('::').last.upcase} (#{send(LNG)} #{send(LAT)})" end |
#type ⇒ Object
45 46 47 |
# File 'lib/carto_json/shape.rb', line 45 def type self.class.type end |