<img align=“right” width=“400” src=“” />

Pinpoint

(Un)conventional Address Composition for Ruby (and Rails)

Supported Rubies

<br/> <br/>

Installation

First:

gem install pinpoint

Then in your script:

require 'pinpoint'

or in your Gemfile

gem 'pinpoint'

or from IRB

irb -r 'pinpoint'

Usage

Direct

Typically Pinpoint is used by requiring it and using the Pinpoint::Address class directly. Like so:

class ThingWithAddress
  attr_accessor :address
end

thing = ThingWithAddress.new
thing.address = Pinpoint::Address.new(:foo => :bar)

Composable

However it can also be included in the class when the class already has accessors for all of the different address attributes to generate a composed address.

class ThingWithAddress
  include Pinpoint::Composable

  attr_accessor :street
  attr_accessor :city
  attr_accessor :state
  attr_accessor :zip_code
  attr_accessor :country

  pinpoint :address
end

thing = ThingWithAddress.new

# Set all address fields on `thing`

thing.address # => Pinpoint::Address

Field Prefixes

If your class has fields that are prefixed by a string (eg venue_city, venue_state, etc) you can pass field_prefix to the compose class method like so:

class ThingWithAddress
  # attr_accessors like:
  attr_accessor :venue_street
  attr_accessor :venue_city

  pinpoint :venue, :field_prefix => 'venue'
end

Address Formatting

Pinpoint has an advanced address formatter which can output an address in multiple country formats.

pinpoint_address.to_s(country:  :us,
                      style:    :one_line)
# => 'Kwik-E-Mart, 123 Apu Lane, Springfield, NW 12345, United States'

pinpoint\_address.to\_s(country:  :ru,
                      style:    :one_line)
# => 'Kwik-E-Mart, ul. Apu Lane d. 123, pos. Springfield, NW obl, 12345, United States'

Note: By default, Pinpoint will format addresses for the country that the address is located in.

Retrieving Address Information

Aliases

Some of the above attributes are aliased to some other common names:

Geocoding

By default, Pinpoint uses {Geocoder}[] to add latitude and longitude information to addresses.

If a Pinpoint address is composed into your class, you can add a :latitude and :longitude attribute to it and it will be set/modified when the address is changed.

Road Map

Issues

If you have problems, please create a Github issue.

Credits

pinpoint is maintained by Chrrpy, LLC

The names and logos for Chirrpy are trademarks of Chrrpy, LLC

Contributors

License

pinpoint is Copyright © 2012 Chirrpy. It is free software, and may be redistributed under the terms specified in the LICENSE file.