<commit_before># My Zipcode Gem

[![MIT-LICENSE](https://img.shields.io/github/license/midwire/my_zipcode_gem.svg)](https://github.com/midwire/my_zipcode_gem/blob/master/MIT-LICENSE)

Simple gem to handle zipcode lookups and related functionality.  `rake zipcodes:update` will automatically download and update your local zipcode database.  Generates three models for extended zipcode functionality.

## Versions

* 0.1.x is for Rails versions less than 4.x
* 0.2.x is for Rails 4 and above

## Installation

Add the following line to your Gemfile:

    gem 'my_zipcode_gem'

Run:

    rake bundle install

Generate the models and populate the data:

```
rails g my_zipcode_gem:models
rake db:migrate
rake zipcodes:update
```

You should now have three new tables and three new models, Zipcode, State, County.

## Usage

```
zipcode = Zipcode.find_by_code '66206'
zipcode.state.abbr    # => 'KS'
zipcode.city          # => 'Shawnee Mission'
zipcode.county.name   # => 'Johnson'
zipcode.lat.to_s      # => '38.959356', it is actually a BigDecimal object converted to_s for documentation.
zipcode.lon.to_s      # => '-94.716155', ditto
zipcode.is_geocoded?  # => true, most if not all should be pre-geocoded.
```

You can also look for a zipcode from a city and state:

    Zipcode.find_by_city_state "Shawnee Mission", "KS"

You can use State and County objects as follows:

```
state = State.find_by_abbr "MO"
state.cities.count    # => 963
state.cities          # gives you a sorted array of all cities for the state
state.zipcodes.count  # => 1195
...
county = state.counties.first
county.cities.count   # => 5
county.cities         # gives you a sorted array of all cities for the county
county.zipcodes.count # => 5
```

### Automatic JQuery/AJAX lookup

You can have a user enter a zipcode and automatically lookup their city, state and county.
<commit_msg>chore(readme): Update API in readme<commit_after># My Zipcode Gem

[![MIT-LICENSE](https://img.shields.io/github/license/midwire/my_zipcode_gem.svg)](https://github.com/midwire/my_zipcode_gem/blob/master/MIT-LICENSE)

Simple gem to handle zipcode lookups and related functionality.  `rake zipcodes:update` will automatically download and update your local zipcode database.  Generates three models for extended zipcode functionality.

## Versions

* 0.1.x is for Rails versions less than 4.x
* 0.2.x is for Rails 4 and above

## Installation

Add the following line to your Gemfile:

    gem 'my_zipcode_gem'

Run:

    rake bundle install

Generate the models and populate the data:

```
rails g my_zipcode_gem:models
rake db:migrate
rake zipcodes:update
```

You should now have three new tables and three new models, Zipcode, State, County.

## Usage

```
zipcode = Zipcode.find_by_code '66206'
zipcode.state.abbr    # => 'KS'
zipcode.city          # => 'Shawnee Mission'
zipcode.county.name   # => 'Johnson'
zipcode.lat.to_s      # => '38.959356', it is actually a BigDecimal object converted to_s for documentation.
zipcode.lon.to_s      # => '-94.716155', ditto
zipcode.geocoded?  # => true, most if not all should be pre-geocoded.
```

You can also look for a zipcode from a city and state:

    Zipcode.find_by_city_state "Shawnee Mission", "KS"

You can use State and County objects as follows:

```
state = State.find_by_abbr "MO"
state.cities.count    # => 963
state.cities          # gives you a sorted array of all cities for the state
state.zipcodes.count  # => 1195
...
county = state.counties.first
county.cities.count   # => 5
county.cities         # gives you a sorted array of all cities for the county
county.zipcodes.count # => 5
```

### Automatic JQuery/AJAX lookup

You can have a user enter a zipcode and automatically lookup their city, state and county.

{'fraction_non_alphanumeric': 0.09858402351055304, 'fraction_numerical': 0.01923590702644937, 'mean_word_length': 3.7694267515923565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5841530', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1182, 'n_words': 416}