Class: Dgrid::API::Place

Inherits:
NamedEntity show all
Defined in:
lib/dgrid/api/place.rb

Instance Attribute Summary collapse

Attributes inherited from NamedEntity

#name

Attributes inherited from Entity

#description, #id, #workspaces

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#add_entity, #add_workspace, #attach, #connection, #first_workspace, #in_workspace?, #link_to, #new_record?, singular, #type, type

Methods included from SetMembersFromHash

#change_string_keys_to_symbol_keys, #set_members_from_hash, #split_hash

Methods included from Dgrid::ArgumentValidation

included

Constructor Details

#initialize(options) ⇒ Place

Returns a new instance of Place.



12
13
14
15
16
17
18
19
20
# File 'lib/dgrid/api/place.rb', line 12

def initialize(options)
	parent_opts, my_opts = split_hash(options,[:name, :description])
	super(parent_opts)
  gps_opts, other_opts = split_hash(options,[:latitude, :longitude, :elevation])
	set_members_from_hash(other_opts)
  if !other_opts.include?(:lat_long) && !gps_opts.empty?
    self.lat_long = coalesce_gps_opts(gps_opts)
  end
end

Instance Attribute Details

#lat_longObject

Returns the value of attribute lat_long.



4
5
6
# File 'lib/dgrid/api/place.rb', line 4

def lat_long
  @lat_long
end

Class Method Details

.db_fieldsObject



23
24
25
# File 'lib/dgrid/api/place.rb', line 23

def self.db_fields
  %w(id name description latitude longitude elevation)
end

.pluralizedObject



27
28
29
# File 'lib/dgrid/api/place.rb', line 27

def self.pluralized
  'places'
end

Instance Method Details

#to_hashObject



31
32
33
34
35
36
37
# File 'lib/dgrid/api/place.rb', line 31

def to_hash
  h = super
  if lat_long
    h.merge!({:latitude => lat_long.lat, :longitude => lat_long.long, :elevation => lat_long.elevation})
  end
  h
end