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.
-
#area ⇒ Object
Returns the value of attribute area.
-
#areacode ⇒ Object
Returns the value of attribute areacode.
-
#endaddr ⇒ Object
Returns the value of attribute endaddr.
-
#endlatitude ⇒ Object
Returns the value of attribute endlatitude.
-
#endlongitude ⇒ Object
Returns the value of attribute endlongitude.
-
#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.
-
#region ⇒ Object
Returns the value of attribute region.
-
#responsecode ⇒ Object
Returns the value of attribute responsecode.
-
#startaddr ⇒ Object
Returns the value of attribute startaddr.
-
#startlatitude ⇒ Object
Returns the value of attribute startlatitude.
-
#startlongitude ⇒ Object
Returns the value of attribute startlongitude.
-
#zipname ⇒ Object
Returns the value of attribute zipname.
Class Method Summary collapse
Instance Method Summary collapse
- #address_string ⇒ Object
- #full_address ⇒ Object
-
#initialize(params) ⇒ Location
constructor
A new instance of Location.
- #to_a ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(params) ⇒ Location
Returns a new instance of Location.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ratis/location.rb', line 8 def initialize(params) @name = params[:name] @area = params[:area] @areacode = params[:areacode] @region = params[:region] @zipname = params[:zipname] @latitude = params[:latitude] @longitude = params[:longitude] @address = params[:address] || '' @landmark_id = params[:landmarkid] || 0 @responsecode = params[:responsecode] @startaddr = params[:startaddr] @endaddr = params[:endaddr] @startlatitude = params[:startlatitude] @startlongitude = params[:startlongitude] @endlatitude = params[:endlatitude] @endlongitude = params[:endlongitude] end |
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 |
#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 |
#endlatitude ⇒ Object
Returns the value of attribute endlatitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def endlatitude @endlatitude end |
#endlongitude ⇒ Object
Returns the value of attribute endlongitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def endlongitude @endlongitude 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 |
#region ⇒ Object
Returns the value of attribute region.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def region @region end |
#responsecode ⇒ Object
Returns the value of attribute responsecode.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def responsecode @responsecode end |
#startaddr ⇒ Object
Returns the value of attribute startaddr.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def startaddr @startaddr end |
#startlatitude ⇒ Object
Returns the value of attribute startlatitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def startlatitude @startlatitude end |
#startlongitude ⇒ Object
Returns the value of attribute startlongitude.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def startlongitude @startlongitude end |
#zipname ⇒ Object
Returns the value of attribute zipname.
5 6 7 |
# File 'lib/ratis/location.rb', line 5 def zipname @zipname end |
Class Method Details
.where(conditions) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ratis/location.rb', line 27 def self.where(conditions) location = conditions.delete :location media = (conditions.delete(:media) || 'W').to_s.upcase max_answers = conditions.delete(:max_answers) || 20 area = conditions.delete(:area) region = conditions.delete(:region) 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, 'Area' => area, 'Region' => region, 'Maxanswers' => max_answers, 'Media' => media } return [] unless response.success? response_code = response.to_hash[:locate_response][:responsecode] locations = response.to_array :locate_response, :location # {:name=>"N 1ST AVE", :area=>"Avondale", :areacode=>"AV", :region=>"1", :zipname=>"85323 - Avondale", :latitude=>"33.436246", :longitude=>"-112.350520", :address=>"101", :landmarkid=>"0"} locations.map do |location_hash| Ratis::Location.new(location_hash.merge(responsecode: response_code)) end end |
Instance Method Details
#address_string ⇒ Object
66 67 68 |
# File 'lib/ratis/location.rb', line 66 def address_string full_address end |
#full_address ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ratis/location.rb', line 70 def full_address temp = "" if address.present? temp << "#{address} #{name} (in #{area})" elsif startaddr.present? temp << "#{startaddr} - #{endaddr} #{name} (in #{area})" else temp << "#{name} (in #{area})" end end |
#to_a ⇒ Object
57 58 59 |
# File 'lib/ratis/location.rb', line 57 def to_a [latitude, longitude, name, landmark_id] end |
#to_hash ⇒ Object
61 62 63 64 |
# File 'lib/ratis/location.rb', line 61 def to_hash keys = [:latitude, :longitude, :name, :area, :address, :startaddr, :endaddr, :address_string, :landmark_id] Hash[keys.map { |k| [k, send(k)] }] end |