https://github.com/mdb/madison.rb
A simple Ruby gem for working with U.S. state names and abbreviations.
https://github.com/mdb/madison.rb
Last synced: about 1 year ago
JSON representation
A simple Ruby gem for working with U.S. state names and abbreviations.
- Host: GitHub
- URL: https://github.com/mdb/madison.rb
- Owner: mdb
- License: mit
- Created: 2012-10-15T19:02:25.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2020-12-05T16:28:18.000Z (over 5 years ago)
- Last Synced: 2025-03-25T17:49:30.926Z (about 1 year ago)
- Language: Ruby
- Size: 30.3 KB
- Stars: 9
- Watchers: 1
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/mdb/madison.rb)
# madison
A dirt simple Ruby gem for working with US state names and abbreviations.
This is the Ruby version of the Node.js [madison](http://github.com/mdb/madison) and was built as an example gem for other developers.
## Installation
The released gem (recommended):
```
$ gem install madison
```
## Usage
Madison can be mixed into a class, or its singleton methods
can be called directly on the `Madison` module.
Require madison:
```ruby
require 'madison'
```
### Include it as a mixin
```ruby
class MyClass
include Madison
end
my_class = MyClass.new
```
Get a state's abbreviation:
```ruby
my_class.state_abbrev 'virginia'
# => VA
```
Get a state's name:
```ruby
my_class.state_name 'va'
# => Virginia
```
Get an array of US state names/abbreviations:
```ruby
my_class.states
# => [
# {
# name: 'Virginia',
# abbr: 'VA'
# },
# ...
#]
```
Get the Madison::Map class used
```ruby
my_class.madison_map
# =>
```
### Use its singleton methods on the Madison module
Get a state's abbreviation:
```ruby
Madison.get_abbrev 'virginia'
# => VA
```
Get a state's name:
```ruby
Madison.get_name 'va'
# => Virginia
```
Get an array of US state names/abbreviations:
```ruby
Madison.states
# => [
# {
# name: 'Virginia',
# abbr: 'VA'
# },
# ...
#]
```