titleize 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/lib/titleize.rb +20 -14
- data/lib/titleize/version.rb +1 -1
- data/spec/titleize_spec.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22d9670a598846e39d7c526c837f7cdce61c52f
|
4
|
+
data.tar.gz: b15abf18dc19969e8949f0e97a18c89b448c0828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7485617fdce1fbca51b6d0805bd0de6eaf76659fcff39e31160e50e08a5be5e1e4805baf37915f61f21812f2d6f09c62c079f6ca687d832980c8ecd9bc3cb82
|
7
|
+
data.tar.gz: 2c58e24dd98c6607b964caaaabeb8ad77e52e7efc6ec9de1f7b014d12e0b2e9a33a4aaff7b617a8673c234d28b9746e5b006a15bf9a6951b6babb7d055d278a0
|
data/History.txt
CHANGED
data/lib/titleize.rb
CHANGED
@@ -23,7 +23,7 @@ module Titleize
|
|
23
23
|
|
24
24
|
phrases(title).map do |phrase|
|
25
25
|
words = phrase.split
|
26
|
-
words.map do |word|
|
26
|
+
words.map.with_index do |word, index|
|
27
27
|
def word.capitalize
|
28
28
|
# like String#capitalize, but it starts with the first letter
|
29
29
|
self.sub(/[[:alpha:]].*/) {|subword| subword.capitalize}
|
@@ -40,10 +40,12 @@ module Titleize
|
|
40
40
|
word
|
41
41
|
when /^[[:digit:]]/ # first character is a number
|
42
42
|
word
|
43
|
-
when words.first, words.last
|
44
|
-
word.capitalize
|
45
43
|
when *(SMALL_WORDS + SMALL_WORDS.map {|small| small.capitalize })
|
46
|
-
|
44
|
+
if index == 0 || index == words.size - 1
|
45
|
+
word.capitalize
|
46
|
+
else
|
47
|
+
word.downcase
|
48
|
+
end
|
47
49
|
else
|
48
50
|
word.capitalize
|
49
51
|
end
|
@@ -56,18 +58,22 @@ module Titleize
|
|
56
58
|
# "simple title" # => ["simple title"]
|
57
59
|
# "more complicated: titling" # => ["more complicated:", "titling"]
|
58
60
|
def phrases(title)
|
59
|
-
phrases =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
phrases[0..-2].each_with_index do |phrase, index|
|
64
|
-
if SMALL_WORDS.include?(phrase.split.last.downcase)
|
65
|
-
phrases[index] << " " + phrases.slice!(index + 1)
|
66
|
-
end
|
67
|
-
end
|
61
|
+
phrases = [[]]
|
62
|
+
title.split.each do |word|
|
63
|
+
phrases.last << word
|
64
|
+
phrases << [] if ends_with_punctuation?(word) && !small_word?(word)
|
68
65
|
end
|
66
|
+
phrases.reject(&:empty?).map { |phrase| phrase.join " " }
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def small_word?(word)
|
72
|
+
SMALL_WORDS.include? word.downcase
|
73
|
+
end
|
69
74
|
|
70
|
-
|
75
|
+
def ends_with_punctuation?(word)
|
76
|
+
word =~ /[:.;?!]$/
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
data/lib/titleize/version.rb
CHANGED
data/spec/titleize_spec.rb
CHANGED
@@ -50,6 +50,7 @@ describe Titleize do
|
|
50
50
|
phrases("this vs. that. no").should == ["this vs. that.", "no"]
|
51
51
|
phrases("this: that vs. him. no. why?").should ==
|
52
52
|
["this:", "that vs. him.", "no.", "why?"]
|
53
|
+
phrases("this vs. that vs. what").should == ["this vs. that vs. what"]
|
53
54
|
end
|
54
55
|
|
55
56
|
it "should handle punctuation combined with a small word as the last word" do
|
@@ -89,6 +90,12 @@ describe Titleize do
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
93
|
+
it "does not capitalize later uses of the first small word" do
|
94
|
+
SMALL_WORDS.each do |word|
|
95
|
+
titleize("#{word} and #{word} are different").should == "#{word.capitalize} and #{word} Are Different"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
92
99
|
it "should capitalize a small word if it is the last word" do
|
93
100
|
SMALL_WORDS.each do |word|
|
94
101
|
titleize("small #{word}").should == "Small #{word.capitalize}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titleize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Hollingworth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: 1.3.6
|
76
76
|
requirements: []
|
77
77
|
rubyforge_project: titleize
|
78
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.6.6
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Adds String#titleize for creating properly capitalized titles.
|