Class: Geocoder::Result::Bag42
- Inherits:
-
Google
- Object
- Geocoder::Result::Bag42
- Defined in:
- lib/bag42_geocoder/results/bag42.rb
Instance Method Summary collapse
- #address(format = :full) ⇒ Object
- #address_components ⇒ Object
-
#address_components_of_type(type) ⇒ Object
Get address components of a given type.
- #city ⇒ Object
- #company_components ⇒ Object
- #company_components_of_type(type) ⇒ Object
-
#coordinates ⇒ Object
Nothing to do here..
- #country ⇒ Object
- #country_code ⇒ Object
- #formatted_address ⇒ Object
- #geometry ⇒ Object
- #postal_code ⇒ Object
- #precision ⇒ Object
- #registered_name ⇒ Object
- #state ⇒ Object
- #state_code ⇒ Object
- #types ⇒ Object
Instance Method Details
#address(format = :full) ⇒ Object
21 22 23 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 21 def address(format = :full) formatted_address end |
#address_components ⇒ Object
81 82 83 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 81 def address_components @data['address_components'] end |
#address_components_of_type(type) ⇒ Object
Get address components of a given type. Valid types are defined in Google’s Geocoding API documentation and include (among others):
:street_number
:locality
:neighborhood
:route
:postal_code
99 100 101 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 99 def address_components_of_type(type) address_components.select{ |c| c['types'].include?(type.to_s) } end |
#city ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 25 def city fields = [:locality, :sublocality, :administrative_area_level_3, :administrative_area_level_2] fields.each do |f| if entity = address_components_of_type(f).first return entity['long_name'] end end return nil # no appropriate components found end |
#company_components ⇒ Object
85 86 87 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 85 def company_components @data['companny_components'] || @data['company_components'] # NOTE: The typo is on purpose! We fallback on non-type to be compatible when they fix this! end |
#company_components_of_type(type) ⇒ Object
103 104 105 106 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 103 def company_components_of_type(type) return [] if company_components.nil? company_components.select{ |c| c['types'].include?(type.to_s) } end |
#coordinates ⇒ Object
Nothing to do here..
17 18 19 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 17 def coordinates ['lat', 'lng'].map{ |i| geometry['location'][i] } end |
#country ⇒ Object
49 50 51 52 53 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 49 def country if country = address_components_of_type(:country).first country['long_name'] end end |
#country_code ⇒ Object
55 56 57 58 59 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 55 def country_code if country = address_components_of_type(:country).first country['short_name'] end end |
#formatted_address ⇒ Object
77 78 79 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 77 def formatted_address @data['formatted_address'] end |
#geometry ⇒ Object
108 109 110 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 108 def geometry @data['geometry'] end |
#postal_code ⇒ Object
61 62 63 64 65 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 61 def postal_code if postal = address_components_of_type(:postcode_code).first postal['long_name'] end end |
#precision ⇒ Object
112 113 114 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 112 def precision geometry['location_type'] if geometry end |
#registered_name ⇒ Object
67 68 69 70 71 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 67 def registered_name if registered_name = company_components_of_type(:registered_name).first registered_name['long_name'] end end |
#state ⇒ Object
37 38 39 40 41 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 37 def state if state = address_components_of_type(:administrative_area_level_1).first state['long_name'] end end |
#state_code ⇒ Object
43 44 45 46 47 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 43 def state_code if state = address_components_of_type(:administrative_area_level_1).first state['short_name'] end end |
#types ⇒ Object
73 74 75 |
# File 'lib/bag42_geocoder/results/bag42.rb', line 73 def types @data['types'] end |