Class: Ratis::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/ratis/location.rb', line 5

def address
  @address
end

#address_stringObject

Returns the value of attribute address_string.



5
6
7
# File 'lib/ratis/location.rb', line 5

def address_string
  @address_string
end

#areaObject

Returns the value of attribute area.



5
6
7
# File 'lib/ratis/location.rb', line 5

def area
  @area
end

#areacodeObject

Returns the value of attribute areacode.



5
6
7
# File 'lib/ratis/location.rb', line 5

def areacode
  @areacode
end

#endaddrObject

Returns the value of attribute endaddr.



5
6
7
# File 'lib/ratis/location.rb', line 5

def endaddr
  @endaddr
end

#landmark_idObject

Returns the value of attribute landmark_id.



5
6
7
# File 'lib/ratis/location.rb', line 5

def landmark_id
  @landmark_id
end

#latitudeObject

Returns the value of attribute latitude.



5
6
7
# File 'lib/ratis/location.rb', line 5

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



5
6
7
# File 'lib/ratis/location.rb', line 5

def longitude
  @longitude
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ratis/location.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/ratis/location.rb', line 5

def response
  @response
end

#startaddrObject

Returns the value of attribute startaddr.



5
6
7
# File 'lib/ratis/location.rb', line 5

def startaddr
  @startaddr
end

Class Method Details

.where(conditions) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ratis/location.rb', line 7

def self.where(conditions)
  location = conditions.delete :location
  media = (conditions.delete(:media) || :w).to_s.upcase
  max_answers = conditions.delete(:max_answers) || 20

  raise ArgumentError.new('You must provide a location') unless location
  raise ArgumentError.new('You must provide media of A|W|I') unless ['A','W','I'].include? media
  raise ArgumentError.new('You must provide a numeric max_answers') unless (Integer max_answers rescue false)
  Ratis.all_conditions_used? conditions

  response = Request.get 'Locate', {'Location' => location, 'Media' => media, 'Maxanswers' => max_answers}
  return [] unless response.success?

  meta = response.to_hash[:locate_response]
  locations = response.to_array :locate_response, :location

  locations.map do |location_hash|
    location = Ratis::Location.new
    location.name = location_hash[:name]
    location.area = location_hash[:area]
    location.response = meta[:responsecode]
    location.areacode = location_hash[:areacode]
    location.latitude = location_hash[:latitude]
    location.longitude = location_hash[:longitude]
    location.landmark_id = location_hash[:landmarkid] || 0
    location.address = location_hash[:address] || ''
    location.startaddr = location_hash[:startaddr] || ''
    location.endaddr = location_hash[:endaddr] || ''
    location.address_string = build_address_string location_hash
    location
  end
end

Instance Method Details

#to_aObject



40
41
42
# File 'lib/ratis/location.rb', line 40

def to_a
  [latitude, longitude, name, landmark_id]
end

#to_hashObject



44
45
46
47
# File 'lib/ratis/location.rb', line 44

def to_hash
  keys = [:latitude, :longitude, :name, :area, :address, :startaddr, :endaddr, :address_string, :landmark_id]
  Hash[keys.map { |k| [k, send(k)] }]
end