aboutsummaryrefslogtreecommitdiff
path: root/app/models/resource.rb
blob: e67d164609017975568c96cd3ebfbb96963d6772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Resource < ApplicationRecord
  # Universally Unique Identifier :uuid
  include UUIDParameter

  belongs_to :agent

  # Figure out the requested property name
  def method_missing(name, *args, &block)
    Rails.logger.info("method_missing: #{name} // #{feature['properties'][name.to_s]}")
    if feature['properties'].key?(name.to_s)
      feature['properties'][name.to_s]
    else
      case name.to_s
      when 'lon', 'longitude'
        feature['geometry']['coordinates'].first
      when 'lat', 'latitude'
        feature['geometry']['coordinates'].last
      when 'geo_type'
        feature['geometry']['type']
      else
        super
      end
    end
  end
end