epitools 0.5.71 → 0.5.72

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
  SHA1:
3
- metadata.gz: b7ec51f36b60a8d9b4197e95cc99ebe03f7ee431
4
- data.tar.gz: 2b82e0fc8a2e95849772e1de9bc6beb8d88a9053
3
+ metadata.gz: 816705da66c484347dcb43b869dd3fdee82a9fb1
4
+ data.tar.gz: 282198552de00f62d799d7cf5181a7d66b77aea8
5
5
  SHA512:
6
- metadata.gz: 1849cdbebc22b12f7f39a34b67d62b9c3f22a56130770b832b6c1add7419316cb3bdcc8cfd2a538c082e83612b4339d67d945e06e9f198d1cc013e86f0681c65
7
- data.tar.gz: fc05462fedcda26792f9b067150cc73491de870607fd3792219118d82730def6a56953f50db3886ee41d23daf7fe08c1a4bcef9f2149478313f3b10f5cdfea32
6
+ metadata.gz: d58bbfe8e37974293691bef4f43d81be8704031e7d09d0a422019966137ebb9337cfc2c95a6acb00a16a7df8d51b51b95e7ee3a70d96f876ab83277b0266a0e8
7
+ data.tar.gz: 4e1ad3abd189c7704d1b3c73321d11441137e450f897c58f8a5dc11705b1f9090e89b13a616ab48f411f5dc2073cb6bb32051e7d6a13a01291865993fa5a2dd2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.71
1
+ 0.5.72
@@ -59,20 +59,32 @@ class String
59
59
  end
60
60
 
61
61
  #
62
- # Convert string to "Title Case" (first letter of each word capitalized)
62
+ # For `titlecase`
63
63
  #
64
- def titlecase!
65
- downcase!
66
- gsub!(/\b\w/) { |m| m.upcase }
67
- end
64
+ LOWERCASE_WORDS = Set.new %w[of to or the and an a at is for from in]
68
65
 
69
66
  #
70
67
  # Return a new string converted to "Title Case" (first letter of each word capitalized)
71
68
  #
72
69
  def titlecase
73
- dup.titlecase!
70
+ first = true
71
+ words = downcase.split(/(?<!\w')\b/)
72
+
73
+ words.map.with_index do |word,i|
74
+ if LOWERCASE_WORDS.include?(word) and i > 0 # leave LOWERCASE_WORDS lowercase, unless it's the first word.
75
+ word
76
+ else
77
+ word.gsub(/^\w/) { |c| c.upcase } # capitalize first letter
78
+ end
79
+ end.join('')
74
80
  end
75
81
 
82
+ #
83
+ # Convert string to "Title Case" (first letter of each word capitalized)
84
+ #
85
+ def titlecase!
86
+ replace(titlecase)
87
+ end
76
88
 
77
89
  #
78
90
  # A Regexp to recognize ANSI escape sequences
@@ -246,9 +246,17 @@ describe String do
246
246
  end
247
247
 
248
248
  it "titlecases" do
249
- "asdf asdfasdf asdf".titlecase.should == "Asdf Asdfasdf Asdf"
250
- " asdf".titlecase.should == " Asdf"
251
- "ASDFASDFA SDF".titlecase.should == "Asdfasdfa Sdf"
249
+ {
250
+ "asdf asdfasdf asdf" => "Asdf Asdfasdf Asdf",
251
+ " asdf" => " Asdf",
252
+ "ASDFASDFA SDF" => "Asdfasdfa Sdf",
253
+ "What's Up" => "What's Up",
254
+ "What's Up" => "What's Up",
255
+ "they're awesome" => "They're Awesome",
256
+ "king of pain" => "King of Pain",
257
+ "a-b-c 1-2-3" => "A-B-C 1-2-3"
258
+ }.each {|orig, titled| orig.titlecase.should == titled }
259
+
252
260
  s = "asdf asdf"
253
261
  s.titlecase!
254
262
  s.should == "Asdf Asdf"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.71
4
+ version: 0.5.72
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron