diff --git a/lib/geocoder/results/mapbox.rb b/lib/geocoder/results/mapbox.rb index f789d325ba6ffea836b0e38f6fd46ab78c7b777c..9e1af899366280899fec92d9ba683c306c719244 100644 --- a/lib/geocoder/results/mapbox.rb +++ b/lib/geocoder/results/mapbox.rb @@ -16,32 +16,38 @@ module Geocoder::Result end def city - @data['context'].map { |c| c['text'] if c['id'] =~ /place/ }.compact.first + context.map { |c| c['text'] if c['id'] =~ /place/ }.compact.first end def state - @data['context'].map { |c| c['text'] if c['id'] =~ /region/ }.compact.first + context.map { |c| c['text'] if c['id'] =~ /region/ }.compact.first end alias_method :state_code, :state def postal_code - @data['context'].map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first + context.map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first end def country - @data['context'].map { |c| c['text'] if c['id'] =~ /country/ }.compact.first + context.map { |c| c['text'] if c['id'] =~ /country/ }.compact.first end alias_method :country_code, :country def neighborhood - @data['context'].map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first + context.map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first end def address [place_name, street, city, state, postal_code, country].compact.join(", ") end + + private + + def context + @data['context'] + end end end