Class: Ratis::Location
- Inherits:
-
Object
- Object
- Ratis::Location
- Defined in:
- lib/ratis/location.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#address_string ⇒ Object
Returns the value of attribute address_string.
-
#area ⇒ Object
Returns the value of attribute area.
-
#areacode ⇒ Object
Returns the value of attribute areacode.
-
#endaddr ⇒ Object
Returns the value of attribute endaddr.
-
#landmark_id ⇒ Object
Returns the value of attribute landmark_id.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#response ⇒ Object
Returns the value of attribute response.
-
#startaddr ⇒ Object
Returns the value of attribute startaddr.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def address @address end |
#address_string ⇒ Object
Returns the value of attribute address_string.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def address_string @address_string end |
#area ⇒ Object
Returns the value of attribute area.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def area @area end |
#areacode ⇒ Object
Returns the value of attribute areacode.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def areacode @areacode end |
#endaddr ⇒ Object
Returns the value of attribute endaddr.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def endaddr @endaddr end |
#landmark_id ⇒ Object
Returns the value of attribute landmark_id.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def landmark_id @landmark_id end |
#latitude ⇒ Object
Returns the value of attribute latitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def name @name end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def response @response end |
#startaddr ⇒ Object
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
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? = 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 = [: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_a ⇒ Object
40 41 42 |
# File 'lib/ratis/location.rb', line 40 def to_a [latitude, longitude, name, landmark_id] end |
#to_hash ⇒ Object
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 |