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

Extract context method

parent 1c306367
No related branches found
No related tags found
No related merge requests found
......@@ -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
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