epitools 0.5.71 → 0.5.72
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/string.rb +18 -6
- data/spec/core_ext_spec.rb +11 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 816705da66c484347dcb43b869dd3fdee82a9fb1
|
4
|
+
data.tar.gz: 282198552de00f62d799d7cf5181a7d66b77aea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d58bbfe8e37974293691bef4f43d81be8704031e7d09d0a422019966137ebb9337cfc2c95a6acb00a16a7df8d51b51b95e7ee3a70d96f876ab83277b0266a0e8
|
7
|
+
data.tar.gz: 4e1ad3abd189c7704d1b3c73321d11441137e450f897c58f8a5dc11705b1f9090e89b13a616ab48f411f5dc2073cb6bb32051e7d6a13a01291865993fa5a2dd2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.72
|
@@ -59,20 +59,32 @@ class String
|
|
59
59
|
end
|
60
60
|
|
61
61
|
#
|
62
|
-
#
|
62
|
+
# For `titlecase`
|
63
63
|
#
|
64
|
-
|
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
|
-
|
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
|
data/spec/core_ext_spec.rb
CHANGED
@@ -246,9 +246,17 @@ describe String do
|
|
246
246
|
end
|
247
247
|
|
248
248
|
it "titlecases" do
|
249
|
-
|
250
|
-
|
251
|
-
|
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"
|