Skip to content
Snippets Groups Projects
Commit 8b7e8e14 authored by sputnik82's avatar sputnik82
Browse files

Extract context_part

parent 794b38b3
No related branches found
No related tags found
No related merge requests found
...@@ -16,27 +16,27 @@ module Geocoder::Result ...@@ -16,27 +16,27 @@ module Geocoder::Result
end end
def city def city
context.map { |c| c['text'] if c['id'] =~ /place/ }.compact.first context_part('place')
end end
def state def state
context.map { |c| c['text'] if c['id'] =~ /region/ }.compact.first context_part('region')
end end
alias_method :state_code, :state alias_method :state_code, :state
def postal_code def postal_code
context.map { |c| c['text'] if c['id'] =~ /postcode/ }.compact.first context_part('postcode')
end end
def country def country
context.map { |c| c['text'] if c['id'] =~ /country/ }.compact.first context_part('country')
end end
alias_method :country_code, :country alias_method :country_code, :country
def neighborhood def neighborhood
context.map { |c| c['text'] if c['id'] =~ /neighborhood/ }.compact.first context_part('neighborhood')
end end
def address def address
...@@ -45,6 +45,10 @@ module Geocoder::Result ...@@ -45,6 +45,10 @@ module Geocoder::Result
private private
def context_part(name)
context.map { |c| c['text'] if c['id'] =~ Regexp.new(name) }.compact.first
end
def context def context
Array(data['context']) Array(data['context'])
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment