From c9588580b79108d1f4c9bf5c467018e2ff62e235 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20C=2E=20Mu=CC=88ller?= <jcmuller@gmail.com>
Date: Tue, 15 Nov 2016 13:06:22 -0500
Subject: [PATCH] Extract context method

---
 lib/geocoder/results/mapbox.rb | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/geocoder/results/mapbox.rb b/lib/geocoder/results/mapbox.rb
index f789d325..9e1af899 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
 
-- 
GitLab