Module: Ekylibre::Record::HasShape

Defined in:
lib/ekylibre/record/has_shape.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.clean_for_active_record(value, options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ekylibre/record/has_shape.rb', line 9

def clean_for_active_record(value, options = {})
  return nil if value.to_s =~ /\A[[:space:]]*\z/
  return value if value.is_a? RGeo::Feature::Instance

  value = if value.is_a?(Hash) || (value.is_a?(String) && value =~ /\A\{.*\}\z/)
            Charta.from_geojson(value)
          else
            Charta.new_geometry(value)
          end
  if options[:type] && options[:type] == :multi_polygon
    value = value.convert_to(:multi_polygon)
  elsif options[:type] && options[:type] == :point
    value = value.convert_to(:point)
  end
  value.to_rgeo
end

.included(base) ⇒ Object


4
5
6
# File 'lib/ekylibre/record/has_shape.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end