Created
April 14, 2014 18:53
-
-
Save JonKernPA/10674021 to your computer and use it in GitHub Desktop.
I spent 15 minutes creating a quick example...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# I spent 15 minutes creating a quick example for an email list... | |
describe "State" do | |
it 'has a list of states' do | |
State.respond_to?(:states) | |
expect(State.states).to have_key('AK') | |
end | |
it '.abbrev' do | |
expect(State.abbrev('Alaska')).to eq('AK') | |
expect(State.abbrev('ohio')).to eq('OH') | |
end | |
it '.state' do | |
expect(State.state('AK')).to eq('Alaska') | |
expect(State.state('pa')).to eq('Pennsylvania') | |
end | |
end | |
class State | |
STATES = { | |
'AK'=> 'Alaska', | |
'PA'=> 'Pennsylvania', | |
'OH'=> 'Ohio', | |
} | |
def self.states | |
STATES | |
end | |
def self.abbrev(state) | |
STATES.invert[state.titleize] | |
end | |
def self.state(abbrev) | |
STATES.fetch(abbrev.upcase) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment