Fixes nil return in the following Geocoder::Result::Mapbox methods: city, state, state_code, postal_code, country, country_code, and neighborhood.
Explanation
Given the following example of a "region" type response, the Geocoder::Result::Mapbox class will not return a value for the state or state_code methods despite the necessary data existing in the payload:
The incumbent logic assumes that there is an array item in context that will have an id containing the "region" string. Since there isn't one, nil is returned from the state and state_code methods. However, the id in the top-level of the object does contain the "region" string because it is a region type response. This means that the top-level text property is the value that should be returned in the state method, and the top-level properties.short_code should be returned as state_code.
This same pattern holds true for the other types of responses. The base payload "type" (id) determines whether or not values for certain methods should be pulled from a context list item or from the base text/properties.
Summary
Fixes
nil
return in the followingGeocoder::Result::Mapbox
methods:city
,state
,state_code
,postal_code
,country
,country_code
, andneighborhood
.Explanation
Given the following example of a "region" type response, the
Geocoder::Result::Mapbox
class will not return a value for thestate
orstate_code
methods despite the necessary data existing in the payload:The incumbent logic assumes that there is an array item in
context
that will have anid
containing the "region" string. Since there isn't one,nil
is returned from thestate
andstate_code
methods. However, theid
in the top-level of the object does contain the "region" string because it is a region type response. This means that the top-leveltext
property is the value that should be returned in thestate
method, and the top-levelproperties.short_code
should be returned asstate_code
.This same pattern holds true for the other types of responses. The base payload "type" (id) determines whether or not values for certain methods should be pulled from a
context
list item or from the basetext
/properties
.