diff --git a/lib/geocoder/results/mapbox.rb b/lib/geocoder/results/mapbox.rb index d5e7ea0f896dc0f994839c523e8190127e0859bb..e458731d2cda17da61c3f0cb75c3778aad174a3b 100644 --- a/lib/geocoder/results/mapbox.rb +++ b/lib/geocoder/results/mapbox.rb @@ -16,27 +16,27 @@ module Geocoder::Result end def city - context.map { |c| c['text'] if c['id'] =~ /place/ }.compact.first + context_part('place') end def state - context.map { |c| c['text'] if c['id'] =~ /region/ }.compact.first + context_part('region') end alias_method :state_code, :state def postal_code - context.map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first + context_part('postcode') end def country - context.map { |c| c['text'] if c['id'] =~ /country/ }.compact.first + context_part('country') end alias_method :country_code, :country def neighborhood - context.map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first + context_part('neighborhood') end def address @@ -45,6 +45,10 @@ module Geocoder::Result private + def context_part(name) + context.map { |c| c['text'] if c['id'] =~ Regexp.new(name) }.compact.first + end + def context Array(data['context']) end