duffy 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9786d17563ae9168426b6f8f6ecc2cf9b4f8480789dd51a14f1f86d39d8be64
4
- data.tar.gz: 3d43f1c5969e3ac08c4abc78339161bfe8368c53fd709fdaabb6395be2458d2b
3
+ metadata.gz: 73762eee91c5b809fa97cbecf522816e751d80d87ab085d8ba29a7aa0971dd37
4
+ data.tar.gz: 41d570f9aa5e93fcf875567f0a689db05770ed58d293aab8997c86860635ec5e
5
5
  SHA512:
6
- metadata.gz: 1b95b5a3a177fd400e583e5550d9542780d3aef2e43b95a7764d456008efc697eeacbbe55fc499e5114bdc263c08a8267650d56319ae306202d9d6bff7fc29bd
7
- data.tar.gz: 735886457662bdbb294bcb4f4b91fa688018698b74a52758e559febac35ba43002c8ce4b0e96477dadcaa2447c28da048f9b8c61efbf684bd21781b1d564a94f
6
+ metadata.gz: 68ba4df32be9196d43b56b30c4ec97c39ae6794cac761f3fc2f5cbd622967a65bec9b1b138664569a153c66e4113ed9988f4547910a8e785f82f5a35e62167b8
7
+ data.tar.gz: 22616030c9bedd21996236912e0eab43d53ad617c5361b4bff7d8ff20b7d6ec95275e951e16883a601d7d92860f9d50448c8e4b3c968b6455f769db1889edc48
@@ -113,11 +113,11 @@ class String
113
113
  string = (self.upcase == self)? self.downcase : self
114
114
 
115
115
  result = ""
116
- string.gsub(/[_-]/, ' ').split(/( [:.;?!][ ] | (?:[ ]|^)[""] )/x).each do |s|
116
+ string.gsub('_', ' ').split(/( [:.;?!][ ] | (?:[ ]|^)[""] )/x).each do |s|
117
117
  s.gsub!(/ \b( [[:alpha:]] [[:lower:].'']* )\b /x) do |w|
118
118
  # Skip words with inresult dots, e.g. "del.icio.us" or "example.com"
119
119
  (w =~ / [[:alpha:]] [.] [[:alpha:]] /x) ? w : w.capitalize
120
- end #gsub!
120
+ end
121
121
 
122
122
  # Lowercase our list of small words:
123
123
  s.gsub!(/\b(#{small_re})\b/io) { |w| w.downcase }
@@ -135,9 +135,19 @@ class String
135
135
  # Special Cases:
136
136
  upcase_re = (Array(Duffy.configuration.upcase_custom) + Array(Duffy.configuration.upcase_default)).uniq.join("|")
137
137
 
138
+ # Names with apostrophes; O'Brian, De'Wayne. 3+ Skips "I've" "Haven't" etc.
139
+ result.gsub!(/([A-Z][a-z]*)'([a-z]{3,})/) { "#{$1}'#{$2.capitalize}" }
140
+
138
141
  result.gsub!(/ V(s?)\. /, ' v\1. ') # "v." and "vs."
142
+
139
143
  result.gsub!(/([''])S\b/, '\1s') # 'S (otherwise you get "the SEC'S decision")
144
+
140
145
  result.gsub!(/\b(#{upcase_re})\b/i) { |w| w.upcase } unless upcase_re.blank?
141
- result
146
+
147
+ # Squash repeated whitespace characters
148
+ result.gsub!(/\s+/, ' ')
149
+
150
+ # Strip leading / tailing whitespace and return
151
+ result.strip
142
152
  end
143
153
  end
@@ -1,8 +1,9 @@
1
1
  module Duffy
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
4
4
 
5
5
  # History
6
+ # 1.0.5 - Update smart_titlecase to better accommodate names.
6
7
  # 1.0.4 - Added battery_percent method.
7
8
  # 1.0.3 - to_box methods now accept ANSI colored strings.
8
9
  # 1.0.2 - Added SimpleCov and added some more String tests.
@@ -27,15 +27,51 @@ describe String do
27
27
  end
28
28
 
29
29
  describe "smart_titlecase" do
30
- { "foo" => "Foo",
31
- "IMPORTANT STUFF" => "Important Stuff",
32
- "123 main st." => "123 Main St.",
33
- "a tale of two cities" => "A Tale of Two Cities"
30
+ {
31
+ "123 Main St." => "123 Main St.", # Numbers are allowed
32
+ "A Tale Of Two Cities" => "A Tale of Two Cities", # Articles are only capitalized if first
33
+ "At mt. Kilimanjaro" => "At Mt. Kilimanjaro", # Small non-articles are capitalized
34
+ "De'wayne" => "De'Wayne", # Names with apostrophes (longer first half)
35
+ "Hyphenated-Lastname" => "Hyphenated-Lastname", # Hyphenated words retain hyphen and capitalize
36
+ "I'm Here Ma'am" => "I'm Here Ma'am", # Contractions are treated as a single word
37
+ "Miller (Smith)" => "Miller (Smith)", # Parentheses are allowed
38
+ "O'brian" => "O'Brian", # Names with apostrophes (single character first half)
39
+ "Sample" => "Sample", # Already Capitalized, all lower, all upper okay
40
+ "Under_scores" => "Under Scores", # Underscores are treated as spaces
41
+
42
+ "Double Space" => "Double Space", # Clear duplicated whitespace
43
+ " Leading Space" => "Leading Space", # Remove leading whitespace
44
+ "Trailing Space " => "Trailing Space", # Remove trailing whitespace
34
45
  }.each do |before, after|
35
- it "#{before.ljust(20)} => #{after}" do
46
+
47
+ # As typed above
48
+ it "#{before.strip.ljust(22)} => #{after}" do
49
+ expect(before.smart_titlecase).to eq after
50
+ end
51
+
52
+ # As all-lowercase
53
+ it "#{before.strip.downcase.ljust(22)} => #{after}" do
54
+ expect(before.downcase.smart_titlecase).to eq after
55
+ end
56
+
57
+ # As all-uppercase
58
+ it "#{before.strip.upcase.ljust(22)} => #{after}" do
59
+ expect(before.upcase.smart_titlecase).to eq after
60
+ end
61
+ end
62
+
63
+ # CamelCase words will be preserved.
64
+ {
65
+ "DreamWorks" => "DreamWorks",
66
+ "McDonald's happy-meal" => "McDonald's Happy-Meal",
67
+ }.each do |before, after|
68
+
69
+ # As typed above
70
+ it "#{before.ljust(22)} => #{after}" do
36
71
  expect(before.smart_titlecase).to eq after
37
72
  end
38
73
  end
74
+
39
75
  end
40
76
 
41
77
  describe "to_alpha" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-20 00:00:00.000000000 Z
11
+ date: 2019-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.0.3
157
+ rubygems_version: 3.0.6
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Library of things