class GoogleMaps::Geocoder::Location
Constants
- ACCURATE_TYPES
- LOCATION_TYPES
- TYPES
Attributes
address_components[RW]
formatted_address[RW]
latitude[RW]
location_type[RW]
longitude[RW]
types[RW]
Public Class Methods
new(json)
click to toggle source
# File lib/google_maps/geocoder/location.rb, line 36 def initialize(json) self.address_components = json['address_components'] self.formatted_address = json['formatted_address'] if geometry_json = json['geometry'] self.location_type = ActiveSupport::StringInquirer.new(geometry_json['location_type'].downcase) if geometry_json['location'] self.latitude = BigDecimal(geometry_json['location']['lat'].to_s) self.longitude = BigDecimal(geometry_json['location']['lng'].to_s) end end self.types = json['types'] end
Public Instance Methods
method_missing(method_sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/google_maps/geocoder/location.rb, line 54 def method_missing(method_sym, *args, &block) if TYPES.include?(method_sym.to_s) define_address_component_accessor_for_type(method_sym) send(method_sym, args.first) else super end end
respond_to?(method_sym, include_private = false)
click to toggle source
Calls superclass method
# File lib/google_maps/geocoder/location.rb, line 63 def respond_to?(method_sym, include_private = false) TYPES.include?(method_sym.to_s) || super end
street_address?()
click to toggle source
# File lib/google_maps/geocoder/location.rb, line 50 def street_address? (ACCURATE_TYPES & self.types).present? end
Private Instance Methods
define_address_component_accessor_for_type(type_symbol)
click to toggle source
# File lib/google_maps/geocoder/location.rb, line 69 def define_address_component_accessor_for_type(type_symbol) class_eval %Q{ def #{type_symbol}(arg=nil) component = address_components.select { |ac| ac['types'].include?('#{type_symbol.to_s}') }.first return nil if component.blank? (arg.to_s == 'short') ? component['short_name'] : component['long_name'] end } end