address_titlecase 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 89a94ec779de3ec14ee166a34206e1b676512f3609809dc13d204b9686e63c75
4
+ data.tar.gz: 972d4ae32751ff4bdecbb93162e683219fcf2f675dd6f294cd52912b04d92cc2
5
+ SHA512:
6
+ metadata.gz: 174280271ff568569298780d87828f9783f94fab655db2e7b126fa1a41333d657b25761325c33129b4aa02ff0850cfdee35d0df3098135e290cde11a6fecc21b
7
+ data.tar.gz: 83bab68c5b9c5492813bc2e8fcfef3c7a4f882e2c3fbae071b532161e74d23ac59c732668d246c41a539140ebf84092da29fa73ff1cbef47718f9eb3117ef84d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+ *.gem
@@ -0,0 +1,5 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
3
+
4
+ Metrics/MethodLength:
5
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.7.0
7
+ before_install: gem install bundler -v 2.1.4
8
+ script:
9
+ - bundle
10
+ - bundle exec rubocop
11
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in address_titlecase.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 juliannaroen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Address Titlecase
2
+
3
+ [![Build Status](https://travis-ci.com/juliannaroen/address_titlecase.svg?token=GqtPi1VKmx9gqq9JuxSW&branch=master)](https://travis-ci.com/juliannaroen/address_titlecase)
4
+
5
+ Titleize US addresses so that states, directions, and other abbreviations that would normally be titlecased by [`String#titleize`](https://apidock.com/rails/String/titleize) remain uppercase.
6
+
7
+ ```ruby
8
+ > "123 SESAME ST SE, SALEM, OR 97301".address_titlecase
9
+ => "123 Sesame St SE, Salem, OR 97301"
10
+ ```
11
+
12
+ ## Options
13
+
14
+ Customize transformations by providing an `overrides` argument where the keys denote the words/abbreviations that should be mapped to specific values.
15
+
16
+ ```ruby
17
+ > "123 SESAME ST SE, SALEM, OR 97301".address_titlecase(overrides: { 'ST' => 'ST', 'SE' => 'Se' })
18
+ => "123 Sesame ST Se, Salem, OR 97301"
19
+ ```
20
+
21
+ `address_titlecase` is also aliased as `address_titleize`.
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'address_titlecase'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install address_titlecase
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'address_titlecase/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'address_titlecase'
9
+ spec.version = AddressTitlecase::VERSION
10
+ spec.authors = ['juliannaroen']
11
+ spec.email = ['jsroen@gmail.com']
12
+
13
+ spec.summary = 'Smartly capitalize US addresses'
14
+ spec.homepage = 'https://github.com/juliannaroen/address_titlecase'
15
+ spec.license = 'MIT'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'pry-byebug'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rubocop'
31
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'address_titlecase'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'address_titlecase/version'
4
+ require 'address_titlecase/titleizer'
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AddressTitlecase
4
+ # AddressTitlecase::Titleizer
5
+ # .titleize
6
+ #
7
+ # Will titlecase a given US address string.
8
+ # Words that should be overridden can be passed as an overrides hash option.
9
+ #
10
+ # Ex:
11
+ # AddressTitlecase::Titleizer.titleize('123 sesame st', overrides: { 'st' => 'ST' }) => '123 Sesame ST'
12
+ class Titleizer
13
+ class << self
14
+ US_STATES = %w[AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY].freeze
15
+ TERRITORIES = %w[AS DC FM GU MH MP PW PR VI].freeze
16
+ MILITARY = %w[APO FPO MPO AE AA AP].freeze
17
+ DIRECTIONS = %w[NE NW SE SW].freeze
18
+ COUNTRIES = %w[USA].freeze
19
+ MISC = %w[PO RR].freeze
20
+
21
+ REMAIN_UPCASE = US_STATES | TERRITORIES | MILITARY | DIRECTIONS | COUNTRIES | MISC
22
+
23
+ def titleize(address, opts)
24
+ overrides = opts['overrides'] || opts[:overrides] || {}
25
+ address.gsub(/\w+['’]?\w*/) do |word|
26
+ overriden_word = overrides[word]
27
+ if overriden_word
28
+ overriden_word
29
+ elsif REMAIN_UPCASE.include?(word.upcase)
30
+ word.upcase
31
+ else
32
+ word.capitalize
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # String
41
+ # .address_titlecase
42
+ #
43
+ # Allow the AddressTitlecase::Titleizer.titleize method to be called on a String object as `address_titlecase`.
44
+ # Method is also aliased to `address_titleize`.
45
+ #
46
+ # Ex:
47
+ # '123 sesame st'.address_titlecase(overrides: {'st' => 'ST'}) => '123 Sesame ST'
48
+ class String
49
+ def address_titlecase(opts = {})
50
+ AddressTitlecase::Titleizer.titleize(self, opts)
51
+ end
52
+
53
+ alias address_titleize address_titlecase
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AddressTitlecase
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: address_titlecase
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - juliannaroen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jsroen@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - address_titlecase.gemspec
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/address_titlecase.rb
101
+ - lib/address_titlecase/titleizer.rb
102
+ - lib/address_titlecase/version.rb
103
+ homepage: https://github.com/juliannaroen/address_titlecase
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Smartly capitalize US addresses
126
+ test_files: []