Module: Muve::Store::Mongo::Formatter

Extended by:
Formatter
Defined in:
lib/muve-store-mongo/formatter.rb

Class Method Summary collapse

Class Method Details

.convert_from_storeable_object(storeable, klass = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/muve-store-mongo/formatter.rb', line 16

def self.convert_from_storeable_object(storeable, klass=nil)
  if klass
    return {
      id: storeable[:id],
      name: storeable[:name],
      location: (Location.new({
        latitude: storeable[:location]["coordinates"][1],
        longitude: storeable[:location]["coordinates"][0]  
      }) if storeable[:location] && storeable[:location]["coordinates"])
    } if (klass < Muve::Place)
  
    return {
      id: storeable[:id],
      time: storeable[:time],
      traveller: Traveller.new(name: storeable[:traveller]),
      location: Location.new(
        latitude: storeable[:location]["coordinates"][1],
        longitude: storeable[:location]["coordinates"][0]
      )
    } if (klass < Muve::Movement)
  end

  if storeable.kind_of? Hash
    if Helper.symbolize_keys(storeable).to_a.include? [:type, 'Place']
      Location.new(latitude: storeable[:coordinates][1], longitude: storeable[:coordinates][0]) if storeable[:coordinates]
    end
  end
end

.convert_to_storeable_object(resource) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/muve-store-mongo/formatter.rb', line 7

def self.convert_to_storeable_object(resource)
  return {
    type: 'Place',
    coordinates: [resource.longitude, resource.latitude]
  } if resource.kind_of? Muve::Location
  return resource.name if resource.kind_of? Muve::Traveller
  resource
end