address_titlecase 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +12 -0
- data/address_titlecase.gemspec +31 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/address_titlecase.rb +4 -0
- data/lib/address_titlecase/titleizer.rb +65 -0
- data/lib/address_titlecase/version.rb +5 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 974492d2050fcf627a4b956c5eeb38ff45e584c1bcb8f0bcb49b90ff05b6757b
|
4
|
+
data.tar.gz: 224eb280d4a96fdbc603a77fc271d24f81e2edd21711f90ee89755435093ec5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 866ba854ceccfb680c1b32ab3eb6278174f76699eedaebac751ab1e6802b41de1e286f504f82098dd687196e600e7621ed5dcd2b9ac7f1f1b1846ca602402e96
|
7
|
+
data.tar.gz: b3aa3695d2d404abae90b2178515fe49b44775d04860b88684bc1f77431068da3dc4deb2431d344d80f65db2767a2f863dfc95751af7debaf5b6e40a79ea36c8
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
+
[![Gem Version](https://badge.fury.io/rb/address_titlecase.svg)](https://badge.fury.io/rb/address_titlecase)
|
5
|
+
|
6
|
+
Titleize US and Canadian addresses so that states, directions, and other abbreviations that would normally be titlecased by [`String#titleize`](https://apidock.com/rails/String/titleize) remain uppercase.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
> "123 SESAME ST SE, SALEM, OR 97301".address_titlecase
|
10
|
+
=> "123 Sesame St SE, Salem, OR 97301"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Options
|
14
|
+
|
15
|
+
Customize transformations by providing an `overrides` argument where the keys denote the words/abbreviations that should be mapped to specific values.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
> "123 SESAME ST SE, SALEM, OR 97301".address_titlecase(overrides: { 'ST' => 'ST', 'SE' => 'Se' })
|
19
|
+
=> "123 Sesame ST Se, Salem, OR 97301"
|
20
|
+
```
|
21
|
+
|
22
|
+
`address_titlecase` is also aliased as `address_titleize`.
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'address_titlecase'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install address_titlecase
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -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', '~> 2.1'
|
27
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.7'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.5'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.72'
|
31
|
+
end
|
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,65 @@
|
|
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
|
+
US_TERRITORIES = %w[AS DC FM GU MH MP PW PR VI].freeze
|
16
|
+
|
17
|
+
CA_PROVINCES = %w[AB BC MB NB NL NS ON PE QC SK].freeze
|
18
|
+
CA_TERRITORIES = %w[NT NU YT].freeze
|
19
|
+
|
20
|
+
MILITARY = %w[APO FPO MPO AE AA AP].freeze
|
21
|
+
|
22
|
+
DIRECTIONS = %w[NE NW SE SW].freeze
|
23
|
+
COUNTRIES = %w[USA].freeze
|
24
|
+
MISC = %w[PO RR].freeze
|
25
|
+
|
26
|
+
REMAIN_UPCASE = US_STATES | US_TERRITORIES | CA_PROVINCES | CA_TERRITORIES | MILITARY | DIRECTIONS | COUNTRIES | MISC
|
27
|
+
|
28
|
+
def titleize(address, opts = {})
|
29
|
+
overrides = opts['overrides'] || opts[:overrides] || {}
|
30
|
+
address.gsub(/\w+['’]?\w*/) do |word|
|
31
|
+
overriden_word = overrides[word]
|
32
|
+
if overriden_word
|
33
|
+
overriden_word
|
34
|
+
elsif REMAIN_UPCASE.include?(word.upcase) || contains_digits?(word)
|
35
|
+
word.upcase
|
36
|
+
else
|
37
|
+
word.capitalize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def contains_digits?(word)
|
45
|
+
!word.count('0-9').zero?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# String
|
52
|
+
# .address_titlecase
|
53
|
+
#
|
54
|
+
# Allow the AddressTitlecase::Titleizer.titleize method to be called on a String object as `address_titlecase`.
|
55
|
+
# Method is also aliased to `address_titleize`.
|
56
|
+
#
|
57
|
+
# Ex:
|
58
|
+
# '123 sesame st'.address_titlecase(overrides: {'st' => 'ST'}) => '123 Sesame ST'
|
59
|
+
class String
|
60
|
+
def address_titlecase(opts = {})
|
61
|
+
AddressTitlecase::Titleizer.titleize(self, opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
alias address_titleize address_titlecase
|
65
|
+
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.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- juliannaroen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-10 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: '2.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
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: '3.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
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.72'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.72'
|
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: []
|