Skip to content

Instantly share code, notes, and snippets.

@maxlinc
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxlinc/6b2f9f64fd25d680971c to your computer and use it in GitHub Desktop.
Save maxlinc/6b2f9f64fd25d680971c to your computer and use it in GitHub Desktop.
URI template sample
template = Addressable::Template.new 'http://open.mapquestapi.com/staticmap/v4/getmap{?key,size,zoom,center}'
template.expand key: 'foo', size: [200, 400], zoom: 5, center: [200, 9]
# => <Addressable::URI:0x3ffb7b824dd8 URI:http://open.mapquestapi.com/staticmap/v4/getmap?key=foo&size=200,400&zoom=5&center=200,9>
template.expand size: [200, 400], center: [200, 9]
# => <Addressable::URI:0x3ffb7b801ce8 URI:http://open.mapquestapi.com/staticmap/v4/getmap?size=200,400&center=200,9>
template.expand size: [200, 400]
# => <Addressable::URI:0x3ffb7a1d3714 URI:http://open.mapquestapi.com/staticmap/v4/getmap?size=200,400>
template = Addressable::Template.new 'http://open.mapquestapi.com/staticmap/v4/getmap{?key}&size={size_x,size_y}{&zoom}&center={center_x,center_y}'
# => <Addressable::Template:0x3ffb7b461174 PATTERN:http://open.mapquestapi.com/staticmap/v4/getmap{?key}&size={size_x,size_y}{&zoom}&center={center_x,center_y}>
template.expand key: 'foo', size_x: 200, size_y: 400, zoom: 5, center_x: 200, center_y: 9
# => <Addressable::URI:0x3ffb7a1cf920 URI:http://open.mapquestapi.com/staticmap/v4/getmap?key=foo&size=200,400&zoom=5&center=200,9>
template.expand size_x: 200, size_y: 400, center_x: 200, center_y: 9
# => <Addressable::URI:0x3ffb7a1e2340 URI:http://open.mapquestapi.com/staticmap/v4/getmap&size=200,400&center=200,9>
template.expand size_x: 200, size_y: 400
# => <Addressable::URI:0x3ffb7b8019c8 URI:http://open.mapquestapi.com/staticmap/v4/getmap&size=200,400&center=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment