titleize 1.0.1 → 1.1.0
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.
- data/History.txt +7 -0
- data/README.txt +1 -1
- data/Rakefile +5 -3
- data/lib/titleize.rb +10 -1
- data/spec/titleize_spec.rb +67 -5
- metadata +50 -11
data/History.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -5,9 +5,11 @@ require 'hoe'
|
|
5
5
|
require './lib/titleize.rb'
|
6
6
|
require 'spec/rake/spectask'
|
7
7
|
|
8
|
-
Hoe.
|
9
|
-
|
10
|
-
|
8
|
+
Hoe.plugin :git
|
9
|
+
|
10
|
+
Hoe.spec "titleize" do
|
11
|
+
developer "Grant Hollingworth", "grant@antiflux.org"
|
12
|
+
remote_rdoc_dir = "" # Release to root
|
11
13
|
end
|
12
14
|
|
13
15
|
desc "Run all specs"
|
data/lib/titleize.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# If loaded in a Rails environment, it modifies Inflector.titleize.
|
7
7
|
module Titleize
|
8
|
-
VERSION = '1.0
|
8
|
+
VERSION = '1.1.0'
|
9
9
|
SMALL_WORDS = %w{a an and as at but by en for if in of on or the to v v. via vs vs.}
|
10
10
|
|
11
11
|
extend self
|
@@ -18,6 +18,9 @@ module Titleize
|
|
18
18
|
# "notes on a scandal" # => "Notes on a Scandal"
|
19
19
|
# "the good german" # => "The Good German"
|
20
20
|
def titleize(title)
|
21
|
+
title = title.dup
|
22
|
+
title.downcase! unless title[/[[:lower:]]/] # assume all-caps need fixing
|
23
|
+
|
21
24
|
phrases(title).map do |phrase|
|
22
25
|
words = phrase.split
|
23
26
|
words.map do |word|
|
@@ -29,8 +32,14 @@ module Titleize
|
|
29
32
|
case word
|
30
33
|
when /[[:alpha:]]\.[[:alpha:]]/ # words with dots in, like "example.com"
|
31
34
|
word
|
35
|
+
when /[-‑]/ # hyphenated word (regular and non-breaking)
|
36
|
+
word.split(/([-‑])/).map do |part|
|
37
|
+
SMALL_WORDS.include?(part) ? part : part.capitalize
|
38
|
+
end.join
|
32
39
|
when /^[[:alpha:]].*[[:upper:]]/ # non-first letter capitalized already
|
33
40
|
word
|
41
|
+
when /^[[:digit:]]/ # first character is a number
|
42
|
+
word
|
34
43
|
when words.first, words.last
|
35
44
|
word.capitalize
|
36
45
|
when *(SMALL_WORDS + SMALL_WORDS.map {|small| small.capitalize })
|
data/spec/titleize_spec.rb
CHANGED
@@ -106,11 +106,61 @@ describe Titleize do
|
|
106
106
|
titleize("iTunes").should == "iTunes"
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
it "should not capitalize words that start with a number" do
|
110
|
+
titleize("2lmc").should == "2lmc"
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "with hyphens" do
|
114
|
+
it "should handle hyphenated words" do
|
115
|
+
titleize("iPhone la-la land").should == "iPhone La-La Land"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should handle non-breaking hyphens" do
|
119
|
+
titleize("non‑breaking hyphen").should == "Non‑Breaking Hyphen"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not capitalize small words within a hyphenated word" do
|
123
|
+
titleize("step-by-step directions").should == "Step-by-Step Directions"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should fix all-caps titles" do
|
128
|
+
titleize("IF IT’S ALL CAPS, FIX IT").should == "If It’s All Caps, Fix It"
|
129
|
+
end
|
130
|
+
|
131
|
+
# test suite from Perl titlecase
|
132
|
+
# http://github.com/ap/titlecase/blob/master/test.pl
|
110
133
|
it "should handle edge cases" do
|
111
134
|
{
|
112
|
-
%{
|
113
|
-
|
135
|
+
%{For step-by-step directions email someone@gmail.com} =>
|
136
|
+
%{For Step-by-Step Directions Email someone@gmail.com},
|
137
|
+
|
138
|
+
%{2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'} =>
|
139
|
+
%{2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'},
|
140
|
+
|
141
|
+
%{Have you read “The Lottery”?} =>
|
142
|
+
%{Have You Read “The Lottery”?},
|
143
|
+
|
144
|
+
%{your hair[cut] looks (nice)} =>
|
145
|
+
%{Your Hair[cut] Looks (Nice)},
|
146
|
+
|
147
|
+
%{People probably won't put http://foo.com/bar/ in titles} =>
|
148
|
+
%{People Probably Won't Put http://foo.com/bar/ in Titles},
|
149
|
+
|
150
|
+
%{Scott Moritz and TheStreet.com’s million iPhone la‑la land} =>
|
151
|
+
%{Scott Moritz and TheStreet.com’s Million iPhone La‑La Land},
|
152
|
+
|
153
|
+
%{BlackBerry vs. iPhone} =>
|
154
|
+
%{BlackBerry vs. iPhone},
|
155
|
+
|
156
|
+
%{Notes and observations regarding Apple’s announcements from ‘The Beat Goes On’ special event} =>
|
157
|
+
%{Notes and Observations Regarding Apple’s Announcements From ‘The Beat Goes On’ Special Event},
|
158
|
+
|
159
|
+
%{Read markdown_rules.txt to find out how _underscores around words_ will be interpretted} =>
|
160
|
+
%{Read markdown_rules.txt to Find Out How _Underscores Around Words_ Will Be Interpretted},
|
161
|
+
|
162
|
+
%{Q&A with Steve Jobs: 'That's what happens in technology'} =>
|
163
|
+
%{Q&A With Steve Jobs: 'That's What Happens in Technology'},
|
114
164
|
|
115
165
|
%{What Is AT&T's Problem?} => %{What Is AT&T's Problem?},
|
116
166
|
|
@@ -144,8 +194,20 @@ describe Titleize do
|
|
144
194
|
%{"Nothing to Be Afraid Of?"} => %{"Nothing to Be Afraid Of?"},
|
145
195
|
%{a thing} => %{A Thing},
|
146
196
|
|
147
|
-
%{
|
148
|
-
%{
|
197
|
+
%{Dr. Strangelove (or: how I Learned to Stop Worrying and Love the Bomb)} =>
|
198
|
+
%{Dr. Strangelove (Or: How I Learned to Stop Worrying and Love the Bomb)},
|
199
|
+
|
200
|
+
%{ this is trimming} =>
|
201
|
+
%{This Is Trimming},
|
202
|
+
|
203
|
+
%{this is trimming } =>
|
204
|
+
%{This Is Trimming},
|
205
|
+
|
206
|
+
%{ this is trimming } =>
|
207
|
+
%{This Is Trimming},
|
208
|
+
|
209
|
+
%{IF IT’S ALL CAPS, FIX IT} =>
|
210
|
+
%{If It’s All Caps, Fix It},
|
149
211
|
}.each do |before, after|
|
150
212
|
titleize(before).should == after
|
151
213
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titleize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 1.1.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Grant Hollingworth
|
@@ -9,19 +14,51 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-03-18 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
21
|
+
name: rubyforge
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
version: 2.0.3
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: gemcutter
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 5
|
44
|
+
- 0
|
45
|
+
version: 0.5.0
|
17
46
|
type: :development
|
18
|
-
|
19
|
-
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hoe
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
20
52
|
requirements:
|
21
53
|
- - ">="
|
22
54
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 5
|
58
|
+
- 0
|
59
|
+
version: 2.5.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
25
62
|
description: |-
|
26
63
|
Adds String#titleize for creating properly capitalized titles.
|
27
64
|
It can be called as Titleize.titleize or "a string".titleize. It is also
|
@@ -54,7 +91,7 @@ files:
|
|
54
91
|
- spec/titleize_spec.rb
|
55
92
|
- spec/spec_helper.rb
|
56
93
|
has_rdoc: true
|
57
|
-
homepage: http://
|
94
|
+
homepage: http://rubygems.org/gems/titleize
|
58
95
|
licenses: []
|
59
96
|
|
60
97
|
post_install_message:
|
@@ -67,18 +104,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
104
|
requirements:
|
68
105
|
- - ">="
|
69
106
|
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 0
|
70
109
|
version: "0"
|
71
|
-
version:
|
72
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
111
|
requirements:
|
74
112
|
- - ">="
|
75
113
|
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
76
116
|
version: "0"
|
77
|
-
version:
|
78
117
|
requirements: []
|
79
118
|
|
80
119
|
rubyforge_project: titleize
|
81
|
-
rubygems_version: 1.3.
|
120
|
+
rubygems_version: 1.3.6
|
82
121
|
signing_key:
|
83
122
|
specification_version: 3
|
84
123
|
summary: Adds String#titleize for creating properly capitalized titles
|