Class: GooglePlaces::Prediction
- Inherits:
-
Object
- Object
- GooglePlaces::Prediction
- Defined in:
- lib/google_places/prediction.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#place_id ⇒ Object
Returns the value of attribute place_id.
-
#terms ⇒ Object
Returns the value of attribute terms.
-
#types ⇒ Object
Returns the value of attribute types.
Class Method Summary collapse
-
.list_by_input(input, api_key, options = {}) ⇒ Object
Query for Predictions (optionally at the provided location).
- .request(method, options) ⇒ Object
Instance Method Summary collapse
-
#initialize(json_result_object) ⇒ Prediction
constructor
A new instance of Prediction.
Constructor Details
#initialize(json_result_object) ⇒ Prediction
Returns a new instance of Prediction.
11 12 13 14 15 16 |
# File 'lib/google_places/prediction.rb', line 11 def initialize(json_result_object) @description = json_result_object['description'] @place_id = json_result_object['place_id'] @terms = json_result_object['terms'] @types = json_result_object['types'] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/google_places/prediction.rb', line 4 def description @description end |
#place_id ⇒ Object
Returns the value of attribute place_id.
4 5 6 |
# File 'lib/google_places/prediction.rb', line 4 def place_id @place_id end |
#terms ⇒ Object
Returns the value of attribute terms.
4 5 6 |
# File 'lib/google_places/prediction.rb', line 4 def terms @terms end |
#types ⇒ Object
Returns the value of attribute types.
4 5 6 |
# File 'lib/google_places/prediction.rb', line 4 def types @types end |
Class Method Details
.list_by_input(input, api_key, options = {}) ⇒ Object
Query for Predictions (optionally at the provided location)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/google_places/prediction.rb', line 35 def self.list_by_input(input, api_key, = {}) lat = .delete(:lat) lng = .delete(:lng) language = .delete(:language) radius = .delete(:radius) = .delete(:retry_options) || {} types = .delete(:types) components = .delete(:components) = { :input => input, :key => api_key, :retry_options => } if lat && lng [:location] = Location.new(lat, lng).format [:radius] = radius if radius end # Accept Types as a string or array if types types = (types.is_a?(Array) ? types.join('|') : types) [:types] = types end if language [:language] = language end if components [:components] = components end request(:predictions_by_input, ) end |
.request(method, options) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/google_places/prediction.rb', line 72 def self.request(method, ) response = Request.send(method, ) response['predictions'].map do |result| self.new(result) end end |