america 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d093dc3fca5ec4fdacdcb0cc3dacff58e91ab01d
4
+ data.tar.gz: ead6ad4fc2e0a59d8b2c8cd7b40cf516c5507e26
5
+ SHA512:
6
+ metadata.gz: b12e836210ba688ce23f6d13936157f8194c63440892362c40fa86f4d1192e48cf032298414f3b0b0870bc07c7d84a7ef8114fb556c9a24e9511a82e03148656
7
+ data.tar.gz: e3f8e0f6b8b18aea3b12a17e0bc8adae33fec42df5501354087bdeb7df8ac29e14093a55fdf2659df2cf12ebceab8f4aed28578ad54ef42130a34b7e0301aa2c
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in america.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Justin Mazzi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # America
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'america'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install america
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/america/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'america/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "america"
8
+ spec.version = America::VERSION
9
+ spec.authors = ["Justin Mazzi"]
10
+ spec.email = ["jmazzi@gmail.com"]
11
+ spec.summary = %q{Convert between state names and abbreviations.}
12
+ spec.description = %q{Convert between state names and abbreviations.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency "activesupport", ">= 3.0.0"
25
+ end
@@ -0,0 +1,87 @@
1
+ require 'active_support/all'
2
+ require "america/version"
3
+
4
+ module America
5
+ class StateName
6
+ STATES = {
7
+ "alabama" => "AL",
8
+ "alaska" => "AK",
9
+ "arizona" => "AZ",
10
+ "arkansas" => "AR",
11
+ "california" => "CA",
12
+ "colorado" => "CO",
13
+ "connecticut" => "CT",
14
+ "delaware" => "DE",
15
+ "florida" => "FL",
16
+ "georgia" => "GA",
17
+ "hawaii" => "HI",
18
+ "idaho" => "ID",
19
+ "illinois" => "IL",
20
+ "indiana" => "IN",
21
+ "iowa" => "IA",
22
+ "kansas" => "KS",
23
+ "kentucky" => "KY",
24
+ "louisiana" => "LA",
25
+ "maine" => "ME",
26
+ "maryland" => "MD",
27
+ "massachusetts" => "MA",
28
+ "michigan" => "MI",
29
+ "minnesota" => "MN",
30
+ "mississippi" => "MS",
31
+ "missouri" => "MO",
32
+ "montana" => "MT",
33
+ "nebraska" => "NE",
34
+ "nevada" => "NV",
35
+ "new hampshire" => "NH",
36
+ "new jersey" => "NJ",
37
+ "new mexico" => "NM",
38
+ "new york" => "NY",
39
+ "north carolina" => "NC",
40
+ "north dakota" => "ND",
41
+ "ohio" => "OH",
42
+ "oklahoma" => "OK",
43
+ "oregon" => "OR",
44
+ "pennsylvania" => "PA",
45
+ "rhode island" => "RI",
46
+ "south carolina" => "SC",
47
+ "south dakota" => "SD",
48
+ "tennessee" => "TN",
49
+ "texas" => "TX",
50
+ "utah" => "UT",
51
+ "vermont" => "VT",
52
+ "virginia" => "VA",
53
+ "washington" => "WA",
54
+ "west virginia" => "WV",
55
+ "wisconsin" => "WI",
56
+ "wyoming" => "WY"
57
+ }
58
+
59
+ attr_reader :state
60
+
61
+ def initialize(state)
62
+ @state = state.to_s.strip
63
+ end
64
+
65
+ def abbreviation
66
+ if abbreviation? && STATES.has_value?(@state.upcase)
67
+ @state.upcase
68
+ else
69
+ STATES[@state.downcase]
70
+ end
71
+ end
72
+
73
+ def fullname
74
+ STATES.key(abbreviation)
75
+ end
76
+
77
+ def known?
78
+ abbreviation.present?
79
+ end
80
+
81
+ private
82
+
83
+ def abbreviation?
84
+ @state.size == 2
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module America
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'america'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module America
4
+ describe StateName do
5
+ context "Converting from state name to abbreviation" do
6
+
7
+ it "returns the abbreviation for known states" do
8
+ state_name = StateName.new('Pennsylvania')
9
+ expect(state_name.abbreviation).to eql('PA')
10
+ end
11
+
12
+ it "ignores whitespace" do
13
+ state_name = StateName.new(' Pennsylvania ')
14
+ expect(state_name.abbreviation).to eql('PA')
15
+ expect(state_name.fullname).to eql('pennsylvania')
16
+ end
17
+
18
+ it "ignores case" do
19
+ state_name = StateName.new('pennsYlvania')
20
+ expect(state_name.abbreviation).to eql('PA')
21
+ expect(state_name.fullname).to eql('pennsylvania')
22
+ end
23
+
24
+ it "known for found states" do
25
+ state_name = StateName.new('Pennsylvania')
26
+ expect(state_name).to be_known
27
+ end
28
+
29
+ it "is not unknow for missing states" do
30
+ state_name = StateName.new('Hamburger')
31
+ expect(state_name).to_not be_known
32
+ end
33
+ end
34
+
35
+ context "Converting from abbreviation to state" do
36
+ it "returns the abbreviation for known states" do
37
+ state_name = StateName.new('PA')
38
+ expect(state_name.abbreviation).to eql('PA')
39
+ end
40
+
41
+ it "ignores whitespace" do
42
+ state_name = StateName.new(' PA ')
43
+ expect(state_name.abbreviation).to eql('PA')
44
+ expect(state_name.fullname).to eql('pennsylvania')
45
+ end
46
+
47
+ it "ignores case" do
48
+ state_name = StateName.new('pA')
49
+ expect(state_name.abbreviation).to eql('PA')
50
+ expect(state_name.fullname).to eql('pennsylvania')
51
+ end
52
+
53
+ it "known for found states" do
54
+ state_name = StateName.new('PA')
55
+ expect(state_name).to be_known
56
+ end
57
+
58
+ it "is not unknow for missing states" do
59
+ state_name = StateName.new('FF')
60
+ expect(state_name).to_not be_known
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: america
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Mazzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ description: Convert between state names and abbreviations.
70
+ email:
71
+ - jmazzi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - america.gemspec
83
+ - lib/america.rb
84
+ - lib/america/version.rb
85
+ - spec/spec_helper.rb
86
+ - spec/state_name_spec.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Convert between state names and abbreviations.
111
+ test_files:
112
+ - spec/spec_helper.rb
113
+ - spec/state_name_spec.rb