crm_formatter 2.5 → 2.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3272fc47f3c2ccd991ce89ab4e7252b7783f306ebc86a3d03a0af49084509d92
4
- data.tar.gz: f0854aa02ed045fde909d4e2240e9cb382240b8e8b2367f618faebb0dc8962de
3
+ metadata.gz: b66f8317ec1e74e46058adc3ed9709f48655ab77edf30f3f84d7551aeda075fd
4
+ data.tar.gz: e5aba562f330b7c9354f56a8864ec09386e05612d15835aadbdc543116144488
5
5
  SHA512:
6
- metadata.gz: 55aee04e100de2b9862d9c09129599e9e5cb1460c1c078c1a1a15a649bea7e42a495f436f3034263e01560633640aae1e312daaf39ddd27ca8750aa30d7c0546
7
- data.tar.gz: b5e4dd5923b92a24f7b7f235b1059e00f66b8bf20bfde316cbbe83982cfe25e2d2073dcfdbd68c80824c02784944695a177ef40a7712c788dd3ec8c2005cf838
6
+ metadata.gz: a15c2adff359992692e7ca2567bb4f7df2eba16154b8390650a3261ea832dcbb75858d88dee9cf5db47ede3af40f250bc9eee25c04cafe7175225189ba25f130
7
+ data.tar.gz: 013ed660aa7e50db5e93be55f28b006af45912b225d49d7d8ab0d8e1feea3b66fa2034c51e1b0428c1e79b3d96ad3ad32fdbc028aeeefef268cfafaef2b2112c
data/README.md CHANGED
@@ -37,6 +37,7 @@ format_urls(array_of_urls)
37
37
  ```
38
38
 
39
39
  1. Format Array of Proper Strings:
40
+
40
41
  Use `format_propers` to format strings with proper nouns, such as (but not limited to):
41
42
 
42
43
  Business Account Names (123 bmw-world => 123 BMW-World),
@@ -49,14 +50,16 @@ Article Titles (the 15 most useful ruby methods => The 15 Most Useful Ruby Metho
49
50
 
50
51
  ```
51
52
  array_of_propers = [
52
- '123 bmw-world',
53
- 'Car-world Kia',
53
+ 'the gmc and bmw-world of AUSTIN tx',
54
+ '123 Car-world Kia OF CHICAGO IL',
55
+ 'Main Street Ford in DALLAS tX',
56
+ 'broad st fiat of houston',
57
+ 'hot-deal auto insurance',
54
58
  'BUDGET - AUTOMOTORES ZONA & FRANCA, INC',
55
59
  'DOWNTOWN CAR REPAIR, INC',
56
60
  'Young Gmc Trucks',
57
61
  'TEXAS TRAVEL, CO',
58
62
  'youmans Chevrolet',
59
- 'Hot-Deal auto Insurance',
60
63
  'quick auto approval, inc',
61
64
  'yazell chevy',
62
65
  'quick cAr LUBE',
@@ -71,77 +74,88 @@ formatted_proper_hashes = CrmFormatter.format_propers(array_of_propers)
71
74
  Formatted Proper Strings:
72
75
 
73
76
  ```
74
- formatted_proper_hashes = [
75
- {
76
- :proper_status=>"formatted",
77
- :proper=>"123 bmw-world",
78
- :proper_f=>"123 BMW-World"
79
- },
80
- {
81
- :proper_status=>"formatted",
82
- :proper=>"Car-world Kia",
83
- :proper_f=>"Car-World Kia"
84
- },
85
- {
86
- :proper_status=>"formatted",
87
- :proper=>"BUDGET - AUTOMOTORES ZONA & FRANCA, INC",
88
- :proper_f=>"Budget - Automotores Zona & Franca, Inc"
89
- },
90
-
91
- {:proper_status=>"formatted",
92
- :proper=>"DOWNTOWN CAR REPAIR, INC",
93
- :proper_f=>"Downtown Car Repair, Inc"
94
- },
95
- {
96
- :proper_status=>"formatted",
97
- :proper=>"Young Gmc Trucks",
98
- :proper_f=>"Young GMC Trucks"
99
- },
100
- {
101
- :proper_status=>"formatted",
102
- :proper=>"TEXAS TRAVEL, CO",
103
- :proper_f=>"Texas Travel, Co"
104
- },
105
- {
106
- :proper_status=>"formatted",
107
- :proper=>"youmans Chevrolet",
108
- :proper_f=>"Youmans Chevrolet"
109
- },
110
- {
111
- :proper_status=>"formatted",
112
- :proper=>"Hot-Deal auto Insurance",
113
- :proper_f=>"Hot-Deal Auto Insurance"
114
- },
115
- {
116
- :proper_status=>"formatted",
117
- :proper=>"quick auto approval, inc",
118
- :proper_f=>"Quick Auto Approval, Inc"
119
- },
120
- {
121
- :proper_status=>"formatted",
122
- :proper=>"yazell chevy",
123
- :proper_f=>"Yazell Chevy"
124
- },
125
- {
126
- :proper_status=>"formatted",
127
- :proper=>"quick cAr LUBE",
128
- :proper_f=>"Quick Car Lube"
129
- },
130
- {
131
- :proper_status=>"formatted",
132
- :proper=>"yAtEs AuTo maLL",
133
- :proper_f=>"Yates Auto Mall"
134
- },
135
- {
136
- :proper_status=>"formatted",
137
- :proper=>"YADKIN VALLEY COLLISION CO",
138
- :proper_f=>"Yadkin Valley Collision Co"
139
- },
140
- {
141
- :proper_status=>"formatted",
142
- :proper=>"XIT FORD INC",
143
- :proper_f=>"Xit Ford Inc"
144
- }
77
+ formatted_proper_hashes =
78
+ [
79
+ {
80
+ proper_status: 'formatted',
81
+ proper: 'the gmc and bmw-world of AUSTIN tx',
82
+ proper_f: 'The GMC and BMW-World of Austin TX'
83
+ },
84
+ {
85
+ proper_status: 'formatted',
86
+ proper: '123 Car-world Kia OF CHICAGO IL',
87
+ proper_f: '123 Car-World Kia of Chicago IL'
88
+ },
89
+ {
90
+ proper_status: 'formatted',
91
+ proper: 'Main Street Ford in DALLAS tX',
92
+ proper_f: 'Main Street Ford in Dallas TX'
93
+ },
94
+ {
95
+ proper_status: 'formatted',
96
+ proper: 'broad st fiat of houston',
97
+ proper_f: 'Broad St Fiat of Houston'
98
+ },
99
+ {
100
+ proper_status: 'formatted',
101
+ proper: 'hot-deal auto insurance',
102
+ proper_f: 'Hot-Deal Auto Insurance'
103
+ },
104
+ {
105
+ proper_status: 'formatted',
106
+ proper: 'BUDGET - AUTOMOTORES ZONA & FRANCA, INC',
107
+ proper_f: 'Budget - Automotores Zona & Franca, Inc'
108
+ },
109
+ {
110
+ proper_status: 'formatted',
111
+ proper: 'DOWNTOWN CAR REPAIR, INC',
112
+ proper_f: 'Downtown Car Repair, Inc'
113
+ },
114
+ {
115
+ proper_status: 'formatted',
116
+ proper: 'Young Gmc Trucks',
117
+ proper_f: 'Young GMC Trucks'
118
+ },
119
+ {
120
+ proper_status: 'formatted',
121
+ proper: 'TEXAS TRAVEL, CO',
122
+ proper_f: 'Texas Travel, Co'
123
+ },
124
+ {
125
+ proper_status: 'formatted',
126
+ proper: 'youmans Chevrolet',
127
+ proper_f: 'Youmans Chevrolet'
128
+ },
129
+ {
130
+ proper_status: 'formatted',
131
+ proper: 'quick auto approval, inc',
132
+ proper_f: 'Quick Auto Approval, Inc'
133
+ },
134
+ {
135
+ proper_status: 'formatted',
136
+ proper: 'yazell chevy',
137
+ proper_f: 'Yazell Chevy'
138
+ },
139
+ {
140
+ proper_status: 'formatted',
141
+ proper: 'quick cAr LUBE',
142
+ proper_f: 'Quick Car Lube'
143
+ },
144
+ {
145
+ proper_status: 'formatted',
146
+ proper: 'yAtEs AuTo maLL',
147
+ proper_f: 'Yates Auto Mall'
148
+ },
149
+ {
150
+ proper_status: 'formatted',
151
+ proper: 'YADKIN VALLEY COLLISION CO',
152
+ proper_f: 'Yadkin Valley Collision Co'
153
+ },
154
+ {
155
+ proper_status: 'formatted',
156
+ proper: 'XIT FORD INC',
157
+ proper_f: 'Xit Ford Inc'
158
+ }
145
159
  ]
146
160
  ```
147
161
 
data/Rakefile CHANGED
@@ -27,21 +27,23 @@ end
27
27
  #############################################
28
28
  def format_propers
29
29
  array_of_propers = [
30
- '123 bmw-world',
31
- 'Car-world Kia',
32
- 'BUDGET - AUTOMOTORES ZONA & FRANCA, INC',
33
- 'DOWNTOWN CAR REPAIR, INC',
34
- 'Young Gmc Trucks',
35
- 'TEXAS TRAVEL, CO',
36
- 'youmans Chevrolet',
37
- 'Hot-Deal auto Insurance',
38
- 'quick auto approval, inc',
39
- 'yazell chevy',
40
- 'quick cAr LUBE',
41
- 'yAtEs AuTo maLL',
42
- 'YADKIN VALLEY COLLISION CO',
43
- 'XIT FORD INC'
44
- ]
30
+ 'the gmc and bmw-world of AUSTIN tx',
31
+ '123 Car-world Kia OF CHICAGO IL',
32
+ 'Main Street Ford in DALLAS tX',
33
+ 'broad st fiat of houston',
34
+ 'hot-deal auto insurance',
35
+ 'BUDGET - AUTOMOTORES ZONA & FRANCA, INC',
36
+ 'DOWNTOWN CAR REPAIR, INC',
37
+ 'Young Gmc Trucks',
38
+ 'TEXAS TRAVEL, CO',
39
+ 'youmans Chevrolet',
40
+ 'quick auto approval, inc',
41
+ 'yazell chevy',
42
+ 'quick cAr LUBE',
43
+ 'yAtEs AuTo maLL',
44
+ 'YADKIN VALLEY COLLISION CO',
45
+ 'XIT FORD INC'
46
+ ]
45
47
 
46
48
  formatted_propers = CrmFormatter.format_propers(array_of_propers)
47
49
  formatted_propers
@@ -5,14 +5,24 @@ module CrmFormatter
5
5
 
6
6
  def letter_case_check(str)
7
7
  return unless str.present?
8
- # str = str.upcase
9
- str = str.upcase.split(' ')&.each { |el| el.capitalize! if el.gsub(/[^ A-Za-z]/, '')&.strip }&.join(' ')
8
+ str = force_capitalize(str)
10
9
  str = capitalize_dashes(str)
11
- str = check_for_brands(str)
10
+ str = force_upcase(str)
11
+ str = force_downcase(str)
12
+ str = force_first_cap(str)
12
13
  str
13
14
  end
14
15
 
16
+ def force_capitalize(str)
17
+ return unless str.present?
18
+ str_parts = str.downcase.split(' ')&.each do |el|
19
+ el.capitalize! if el.gsub(/[^ A-Za-z]/, '')&.strip
20
+ end
21
+ str = str_parts&.join(' ')
22
+ end
23
+
15
24
  def capitalize_dashes(str)
25
+ return unless str.present?
16
26
  if str&.include?('-')
17
27
  els = str.split(' ')
18
28
  dash_els = els.select { |el| el != '-' && el.include?('-') }
@@ -25,12 +35,53 @@ module CrmFormatter
25
35
  str
26
36
  end
27
37
 
28
- def check_for_brands(str)
38
+ def force_upcase(str)
39
+ return unless str.present?
40
+ str = add_space(str)
41
+
42
+ grab_ups.map do |up|
43
+ str = str.gsub(" #{up.capitalize} ", " #{up} ")
44
+ str = str.gsub(" #{up.capitalize}-", " #{up}-")
45
+ str = str.gsub("-#{up.capitalize} ", "-#{up} ")
46
+ end
47
+ str = strip_squeeze(str)
48
+ end
49
+
50
+ def force_downcase(str)
29
51
  return unless str.present?
30
- ['BMW', 'CDJR', 'CJDR', 'GMC', 'CJD'].map do |brand|
31
- str = str.gsub(brand.capitalize, brand)
52
+ str = add_space(str)
53
+
54
+ grab_downs.map do |down|
55
+ str = str.gsub(" #{down.capitalize} ", " #{down} ")
32
56
  end
33
- str
57
+ str = strip_squeeze(str)
58
+ end
59
+
60
+ def force_first_cap(str)
61
+ str = "#{str[0].upcase}#{str[1..-1]}"
62
+ end
63
+
64
+ def add_space(str)
65
+ return unless str.present?
66
+ str = " #{str} "
67
+ end
68
+
69
+ def strip_squeeze(str)
70
+ str = str.squeeze(" ")
71
+ str = str.strip
72
+ end
73
+
74
+ def grab_downs
75
+ downs = %w[and as both but either for from in just neither nor of only or out so the to whether with yet]
76
+ end
77
+
78
+ def grab_ups
79
+ ups = %w[I]
80
+ brands = %w[BMW CDJR CJDR GMC CJD I]
81
+ professional = %w[BA BS MA JD DC PA MD VP SVP EVP CMO CFO CEO]
82
+ states = %w[AK AL AR AZ CA CT DC DE FL GA HI IA ID IL KS KY LA MA MD MI MN MO NC ND NE NH NJ NM NV NY OH OK PA RI SC SD TN TX UT VA VT WA WI WV WY]
83
+ directions = %w[NE NW SE SW]
84
+ ups = [brands, professional, states, directions].flatten.uniq
34
85
  end
35
86
 
36
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module CrmFormatter
4
- VERSION = "2.5"
4
+ VERSION = "2.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crm_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.5'
4
+ version: '2.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Booth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry