unicode_titlecase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +103 -0
- data/Rakefile +6 -0
- data/lib/unicode_titlecase/core_ext/string.rb +73 -0
- data/lib/unicode_titlecase/version.rb +3 -0
- data/lib/unicode_titlecase.rb +2 -0
- data/spec/examples/bigword_examples.yaml +28 -0
- data/spec/examples/capitalisation_examples.yaml +31 -0
- data/spec/examples/smallword_examples.yaml +4 -0
- data/spec/examples/standard_examples.yaml +70 -0
- data/spec/examples/unicode_examples.yaml +31 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/unicode_titlecase_spec.rb +53 -0
- data/unicode_titlecase.gemspec +24 -0
- metadata +124 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# Ignore /vendor directory, including gems vendored by bundle install --path
|
20
|
+
/vendor
|
21
|
+
|
22
|
+
# Ignore binstubs generated by bundle install --binstubs
|
23
|
+
/bin
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p448
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chong-Yee Khoo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# unicode_titlecase gem
|
2
|
+
|
3
|
+
A set of methods added onto the String class to allow easy title casing of strings with Unicode text.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* handles Unicode text
|
8
|
+
* specify words that should always be left capitalised
|
9
|
+
* specify words that should always be left in lower case
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'unicode_titlecase'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install unicode_titlecase e'.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
This gem patches the String class to provide a unicode_titlecase method, which returns a string that is 'title cased': the first letter in each significant word is in capitals with the rest in lowercase.
|
28
|
+
|
29
|
+
To use, just call the unicode_titlecase method on any string you want to titlecase.
|
30
|
+
|
31
|
+
For example,
|
32
|
+
|
33
|
+
require 'unicode_titlecase'
|
34
|
+
|
35
|
+
s = "the rain in spain stays mainly in the plain"
|
36
|
+
puts s.unicode_titlecase
|
37
|
+
|
38
|
+
gives
|
39
|
+
|
40
|
+
"The Rain in Spain Stays Mainly in the Plain"
|
41
|
+
|
42
|
+
More examples are set out in the YAML files in the /spec/examples directory.
|
43
|
+
|
44
|
+
## Unicode Text
|
45
|
+
|
46
|
+
With the help of the unicode-utils gem, we can properly handle title casing of Unicode text.
|
47
|
+
|
48
|
+
For example, the string 'W Hiszpanii mży, gdy dżdżyste przyjdą dni' will be titlecased to 'W Hiszpanii Mży, Gdy Dżdżyste Przyjdą Dni'.
|
49
|
+
|
50
|
+
Note: the source text may contain Unicode, or it may consist solely of ASCII. The unicode_titlecase method will work with either.
|
51
|
+
|
52
|
+
## 'Big Words'
|
53
|
+
|
54
|
+
In some circumstances, you may have source text that contains words that should remain capitalised. These include Roman numerals ('VIII'), legal entity designations ('SA', 'AB', 'LLC') or technical abbreviations ('RNA', DNA', 'HIV').
|
55
|
+
|
56
|
+
The unicode_titlecase gem allows you to set up a list of 'big words' which it will keep upper-cased.
|
57
|
+
|
58
|
+
## 'Small Words'
|
59
|
+
|
60
|
+
Similarly, you source text may contain words that should always be in lower case.
|
61
|
+
|
62
|
+
By convention, a number of short words such as 'is', 'of' and 'by' are considered to look better in text if they remain in lower case.
|
63
|
+
|
64
|
+
For example, the phrase 'a government by the people for the people' might be title cased to 'A Government by the People for the People'.
|
65
|
+
|
66
|
+
## Sources and Acknowledgements
|
67
|
+
|
68
|
+
Much of the source is based on Sam Souder's 'titlecase' gem at [samsouder/titlecase] (http://github.com/samsouder/titlecase) which in turn is derived from the [rules] (http://daringfireball.net/2008/05/title_case) formulated by John Gruber.
|
69
|
+
|
70
|
+
#### Gruber's Rules
|
71
|
+
- capitalize each word
|
72
|
+
- downcase each of the small_words
|
73
|
+
- words with capitals after the first character are left alone
|
74
|
+
- words with periods are left alone
|
75
|
+
- first and last word always capitalized
|
76
|
+
- small words after colons are capitalized
|
77
|
+
|
78
|
+
#### titlecase gem by samsouder
|
79
|
+
|
80
|
+
- implemented rules in Ruby
|
81
|
+
- [Github repo] (http://github.com/samsouder/titlecase)
|
82
|
+
- [Rubygems.org] (http://rubygems.org/gems/titlecase)
|
83
|
+
|
84
|
+
#### Others
|
85
|
+
- Jim Nanney ([Github](https://github.com/jimnanney)) contributed to some of the code (go remote pairing!)
|
86
|
+
|
87
|
+
## Further Features?
|
88
|
+
Here's a list of things we'd like to see in a future version of the unicode_titlecase gem. Please feel free to take any of these on (see [Contributing] (http://github.com/cantab/unicode_titlecase#contributing) below).
|
89
|
+
- handle strings with 'mixed case words' such as GmbH
|
90
|
+
- place exceptions into separate files in e.g., YAML (instead of storing in local variables)
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
Feel free to drop us a line to let us know you would like to work on something or if you have an idea. Otherwise, fork, code, commit, push and create pull request, *viz*:
|
94
|
+
|
95
|
+
1. Create a fork of the repo from http://github.com/cantab/unicode_titlecase.
|
96
|
+
2. Create your feature branch (`git checkout -b new-feature`).
|
97
|
+
2. Write some tests (in RSpec, if you please).
|
98
|
+
3. Write the code that allows the tests to pass.
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
100
|
+
4. Push to the branch (`git push origin new-feature`).
|
101
|
+
5. Create a new [Pull Request] (https://help.github.com/articles/using-pull-requests).
|
102
|
+
|
103
|
+
More details on how to contribute can be found at this great Thoughtbot blogpost [8 (new) steps for fixing other people's code] (http://robots.thoughtbot.com/8-new-steps-for-fixing-other-peoples-code).
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'unicode_utils'
|
4
|
+
|
5
|
+
module UnicodeTitlecase
|
6
|
+
module CoreExt
|
7
|
+
module String
|
8
|
+
|
9
|
+
def unicode_titlecase
|
10
|
+
# List of exceptions: small_words are words that should always be in lowercase; big_words are words that should always be in uppercase
|
11
|
+
small_words = %w(a an and as at but by be for if in is of on or the to v v. via vs vs.)
|
12
|
+
big_words = %w(AB A.B. A/B AS A.S. A/S S.A. KG LLC LLP DNA RNA HBV HIV I II III IV V VI VII VIII IX X AC DC Q&A AT&T)
|
13
|
+
|
14
|
+
x = split(" ").map do |word|
|
15
|
+
# note: word could contain non-word characters!
|
16
|
+
# downcase all small_words, upcase all big words, smart capitalize the rest
|
17
|
+
|
18
|
+
word.replace(UnicodeUtils.downcase(word)) if word.all_caps? and not big_words.include?(word)
|
19
|
+
|
20
|
+
if small_words.include?(UnicodeUtils.downcase(word.gsub(/\W/, "")))
|
21
|
+
word.replace(UnicodeUtils.downcase(word))
|
22
|
+
else
|
23
|
+
if big_words.include?(UnicodeUtils.upcase(word.gsub(/\W/, "")))
|
24
|
+
word.replace(UnicodeUtils.upcase(word))
|
25
|
+
else
|
26
|
+
word.smart_capitalize!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
x = x - [' ']
|
32
|
+
|
33
|
+
# capitalize first and last words
|
34
|
+
x.first.to_s.smart_capitalize!
|
35
|
+
# Uncomment the next line if you want the last word to be always initial caps
|
36
|
+
x.last.to_s.smart_capitalize!
|
37
|
+
|
38
|
+
# small words after colons are capitalized
|
39
|
+
x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " }
|
40
|
+
end
|
41
|
+
|
42
|
+
def unicode_titlecase!
|
43
|
+
replace(unicode_titlecase)
|
44
|
+
end
|
45
|
+
|
46
|
+
def smart_capitalize
|
47
|
+
# ignore any leading crazy characters and capitalize the first real character
|
48
|
+
if self =~ /^['"\(\[']*(\S)/
|
49
|
+
i = index($1)
|
50
|
+
x = self[i,self.length]
|
51
|
+
# word with capitals and periods mid-word are left alone
|
52
|
+
self[i,1] = UnicodeUtils.upcase(self[i,1]) unless self.has_caps? or x =~ /\.\w+/
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def smart_capitalize!
|
58
|
+
replace(smart_capitalize)
|
59
|
+
end
|
60
|
+
|
61
|
+
def has_caps?
|
62
|
+
return !UnicodeUtils.downcase(self) == self
|
63
|
+
end
|
64
|
+
|
65
|
+
def all_caps?
|
66
|
+
return UnicodeUtils.upcase(self) == self
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
String.send :include, UnicodeTitlecase::CoreExt::String
|
@@ -0,0 +1,28 @@
|
|
1
|
+
should_pass:
|
2
|
+
-
|
3
|
+
example: "Scientists discover DNA body clock"
|
4
|
+
expect: "Scientists Discover DNA Body Clock"
|
5
|
+
-
|
6
|
+
example: "Swedish firm Fingerprint Cards AB"
|
7
|
+
expect: "Swedish Firm Fingerprint Cards AB"
|
8
|
+
-
|
9
|
+
example: "Swedish firm Fingerprint Cards A.B."
|
10
|
+
expect: "Swedish Firm Fingerprint Cards A.B."
|
11
|
+
-
|
12
|
+
example: "Swedish firm Fingerprint Cards A/B"
|
13
|
+
expect: "Swedish Firm Fingerprint Cards A/B"
|
14
|
+
-
|
15
|
+
example: "Liver cancer often diagnosed late with poor survival in people with HIV"
|
16
|
+
expect: "Liver Cancer Often Diagnosed Late With Poor Survival in People With HIV"
|
17
|
+
-
|
18
|
+
example: "A limited liability company (LLC) is legal entity"
|
19
|
+
expect: "A Limited Liability Company (LLC) is Legal Entity"
|
20
|
+
-
|
21
|
+
example: "Cantab LLP; small but perfectly formed"
|
22
|
+
expect: "Cantab LLP; Small but Perfectly Formed"
|
23
|
+
-
|
24
|
+
example: "a limited liability company (llc) is a legal entity"
|
25
|
+
expect: "A Limited Liability Company (LLC) is a Legal Entity"
|
26
|
+
-
|
27
|
+
example: "cantab llp. small but perfectly formed"
|
28
|
+
expect: "Cantab LLP. Small but Perfectly Formed"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
should_pass:
|
2
|
+
-
|
3
|
+
example: "THIS IS AN EXAMPLE OF A SENTENCE THAT STARTS OFF IN ALL CAPS"
|
4
|
+
expect: "This is an Example of a Sentence That Starts Off in All Caps"
|
5
|
+
-
|
6
|
+
example: "This is an example of the same sentence that does not start off in all caps"
|
7
|
+
expect: "This is an Example of the Same Sentence That Does Not Start Off in All Caps"
|
8
|
+
-
|
9
|
+
example: "THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN"
|
10
|
+
expect: "The Rain in Spain Stays Mainly in the Plain"
|
11
|
+
-
|
12
|
+
example: "The rain in Spain stays mainly in the plain"
|
13
|
+
expect: "The Rain in Spain Stays Mainly in the Plain"
|
14
|
+
-
|
15
|
+
example: "THE VITAMINS ARE IN MY FRESH CALIFORNIA RAISINS"
|
16
|
+
expect: "The Vitamins Are in My Fresh California Raisins"
|
17
|
+
-
|
18
|
+
example: "MULTI-LAYER OPTICAL DISC"
|
19
|
+
expect: "Multi-layer Optical Disc"
|
20
|
+
-
|
21
|
+
example: "Multi-layer optical disc"
|
22
|
+
expect: "Multi-layer Optical Disc"
|
23
|
+
-
|
24
|
+
example: "SUN, Yat-Sen"
|
25
|
+
expect: "Sun, Yat-Sen"
|
26
|
+
-
|
27
|
+
example: "SUN, Yat-sen"
|
28
|
+
expect: "Sun, Yat-sen"
|
29
|
+
-
|
30
|
+
example: "SUN, YAT-SEN"
|
31
|
+
expect: "Sun, Yat-sen"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
should_pass:
|
2
|
+
-
|
3
|
+
example: "The rain in spain stays mainly on the plain"
|
4
|
+
expect: "The Rain in Spain Stays Mainly on the Plain"
|
5
|
+
-
|
6
|
+
example: "Q&A with Steve Jobs: 'That's what happens in technology'"
|
7
|
+
expect: "Q&A With Steve Jobs: 'That's What Happens in Technology'"
|
8
|
+
-
|
9
|
+
example: "what is AT&T's problem?"
|
10
|
+
expect: "What is AT&T's Problem?"
|
11
|
+
-
|
12
|
+
example: "Apple deal with AT&T falls through"
|
13
|
+
expect: "Apple Deal With AT&T Falls Through"
|
14
|
+
-
|
15
|
+
example: "this v that"
|
16
|
+
expect: "This v That"
|
17
|
+
-
|
18
|
+
example: "this vs that"
|
19
|
+
expect: "This vs That"
|
20
|
+
-
|
21
|
+
example: "this v. that"
|
22
|
+
expect: "This v. That"
|
23
|
+
-
|
24
|
+
example: "this vs. that"
|
25
|
+
expect: "This vs. That"
|
26
|
+
-
|
27
|
+
example: "The SEC's Apple probe: what you need to know"
|
28
|
+
expect: "The SEC's Apple Probe: What You Need to Know"
|
29
|
+
-
|
30
|
+
example: "'by the way, small word at the start but within quotes.'"
|
31
|
+
expect: "'By the Way, Small Word at the Start but Within Quotes.'"
|
32
|
+
-
|
33
|
+
example: "small word at end is nothing to be afraid of"
|
34
|
+
expect: "Small Word at End is Nothing to be Afraid Of"
|
35
|
+
-
|
36
|
+
example: "Starting Sub-Phrase with a small word: a trick, perhaps?"
|
37
|
+
expect: "Starting Sub-Phrase With a Small Word: A Trick, Perhaps?"
|
38
|
+
-
|
39
|
+
example: "Sub-Phrase With a Small Word in Quotes: 'a trick, perhaps?'"
|
40
|
+
expect: "Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'"
|
41
|
+
-
|
42
|
+
example: "Sub-Phrase With a Small Word in Quotes: \"a trick, perhaps?\""
|
43
|
+
expect: "Sub-Phrase With a Small Word in Quotes: \"A Trick, Perhaps?\""
|
44
|
+
-
|
45
|
+
example: "\"nothing to be afraid of?\""
|
46
|
+
expect: "\"Nothing to be Afraid Of?\""
|
47
|
+
-
|
48
|
+
example: "a thing"
|
49
|
+
expect: "A Thing"
|
50
|
+
-
|
51
|
+
example: "2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"
|
52
|
+
expect: "2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"
|
53
|
+
-
|
54
|
+
example: "a complex thing"
|
55
|
+
expect: "A Complex Thing"
|
56
|
+
-
|
57
|
+
example: "de.licio.us: the new hotness?"
|
58
|
+
expect: "de.licio.us: The New Hotness?"
|
59
|
+
-
|
60
|
+
example: "introducing: de.licio.us bookmarks"
|
61
|
+
expect: "Introducing: de.licio.us Bookmarks"
|
62
|
+
-
|
63
|
+
example: "i end in a period."
|
64
|
+
expect: "I End in a Period."
|
65
|
+
-
|
66
|
+
example: "this is a test.com!?"
|
67
|
+
expect: "This is a test.com!?"
|
68
|
+
-
|
69
|
+
example: ""
|
70
|
+
expect: ""
|
@@ -0,0 +1,31 @@
|
|
1
|
+
should_pass:
|
2
|
+
-
|
3
|
+
example: "W Hiszpanii mży, gdy dżdżyste przyjdą dni"
|
4
|
+
expect: "W Hiszpanii Mży, Gdy Dżdżyste Przyjdą Dni"
|
5
|
+
-
|
6
|
+
example: "AVANGART KURUTMA TEKNOLOJİLERİ SANAYİ İÇ VE DIŞ TİCARET LİMİLED ŞİRKETİ"
|
7
|
+
expect: "Avangart Kurutma Teknoloji̇leri̇ Sanayi̇ İÇ Ve Diş Ti̇caret Li̇mi̇led Şi̇rketi̇"
|
8
|
+
-
|
9
|
+
example: "МНОГОСЛОЙНЫЙ ОПТИЧЕСКИЙ ДИСК"
|
10
|
+
expect: "Многослойный Оптический Диск"
|
11
|
+
-
|
12
|
+
example: "УСТРОЙСТВО ДЛЯ ЗАПИСИ-СТИРАНИЯ-СЧИТЫВАНИЯ ИНФОРМАЦИИ В МНОГОСЛОЙНОМ ОПТИЧЕСКОМ ДИСКЕ"
|
13
|
+
expect: "Устройство Для Записи-стирания-считывания Информации В Многослойном Оптическом Диске"
|
14
|
+
-
|
15
|
+
example: "УСТРОЙСТВО ДЛЯ СБОРА СОСУЛЕК"
|
16
|
+
expect: "Устройство Для Сбора Сосулек"
|
17
|
+
-
|
18
|
+
example: "KIYKO, Vаdim Vеniаminоviсh, dеr. Khоdаеvо, 75, Сhеkhоvsky r-n, Моskоvskауа оbl., 142302"
|
19
|
+
expect: "Kiyko, Vаdim Vеniаminоviсh, Dеr. Khоdаеvо, 75, Сhеkhоvsky R-n, Моskоvskауа Оbl., 142302"
|
20
|
+
-
|
21
|
+
example: "hyvää huomenta"
|
22
|
+
expect: "Hyvää Huomenta"
|
23
|
+
-
|
24
|
+
example: "孫中山"
|
25
|
+
expect: "孫中山"
|
26
|
+
-
|
27
|
+
example: "Sūn Zhōngshān"
|
28
|
+
expect: "Sūn Zhōngshān"
|
29
|
+
-
|
30
|
+
example: "sūn zhōngshān nányáng jìniàn guǎn"
|
31
|
+
expect: "Sūn Zhōngshān Nányáng Jìniàn Guǎn"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'unicode_titlecase'
|
4
|
+
require 'yaml'
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
def run_examples_from_file(filename)
|
8
|
+
|
9
|
+
File.open(File.join(File.dirname(__FILE__), "examples/", *filename)) do |file|
|
10
|
+
examples = YAML.load(file)
|
11
|
+
examples["should_pass"].each do |e|
|
12
|
+
it "#{e["example"]} when titlecased is the expected value (#{e["expect"]})" do
|
13
|
+
expect(e["example"].unicode_titlecase).to eq(e["expect"])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
let(:string) { 'the rain in spain' }
|
6
|
+
|
7
|
+
describe "unicode_titlecase method" do
|
8
|
+
|
9
|
+
it "returns a title cased version of the string" do
|
10
|
+
expect(string.unicode_titlecase).to eq('The Rain in Spain')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not modify the original string" do
|
14
|
+
string.unicode_titlecase
|
15
|
+
expect(string).to eq('the rain in spain')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "unicode_titlecase! method" do
|
20
|
+
|
21
|
+
it "returns a title cased version of the string" do
|
22
|
+
expect(string.unicode_titlecase!).to eq('The Rain in Spain')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "self-modifies the original value in place" do
|
26
|
+
string.unicode_titlecase!
|
27
|
+
expect(string).to eq('The Rain in Spain')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "examples" do
|
32
|
+
|
33
|
+
describe "bigword examples" do
|
34
|
+
run_examples_from_file('bigword_examples.yaml')
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "capitalisation examples" do
|
38
|
+
run_examples_from_file('capitalisation_examples.yaml')
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "smallword examples" do
|
42
|
+
run_examples_from_file('smallword_examples.yaml')
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "standard examples" do
|
46
|
+
run_examples_from_file('standard_examples.yaml')
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "unicode examples" do
|
50
|
+
run_examples_from_file('unicode_examples.yaml')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'unicode_titlecase/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "unicode_titlecase"
|
8
|
+
gem.version = UnicodeTitlecase::VERSION
|
9
|
+
gem.authors = ["Chong-Yee Khoo"]
|
10
|
+
gem.email = ["mail@cykhoo.com"]
|
11
|
+
gem.description = %q{Titlecaser with Unicode smarts}
|
12
|
+
gem.summary = %q{Change text, including in Unicode, to title case}
|
13
|
+
gem.homepage = "http://github.com/cykhoo/unicode_titlecase"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'unicode_utils'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unicode_titlecase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chong-Yee Khoo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: unicode_utils
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Titlecaser with Unicode smarts
|
63
|
+
email:
|
64
|
+
- mail@cykhoo.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .ruby-version
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- lib/unicode_titlecase.rb
|
77
|
+
- lib/unicode_titlecase/core_ext/string.rb
|
78
|
+
- lib/unicode_titlecase/version.rb
|
79
|
+
- spec/examples/bigword_examples.yaml
|
80
|
+
- spec/examples/capitalisation_examples.yaml
|
81
|
+
- spec/examples/smallword_examples.yaml
|
82
|
+
- spec/examples/standard_examples.yaml
|
83
|
+
- spec/examples/unicode_examples.yaml
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/unicode_titlecase_spec.rb
|
86
|
+
- unicode_titlecase.gemspec
|
87
|
+
homepage: http://github.com/cykhoo/unicode_titlecase
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: -1860229550247952293
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -1860229550247952293
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Change text, including in Unicode, to title case
|
117
|
+
test_files:
|
118
|
+
- spec/examples/bigword_examples.yaml
|
119
|
+
- spec/examples/capitalisation_examples.yaml
|
120
|
+
- spec/examples/smallword_examples.yaml
|
121
|
+
- spec/examples/standard_examples.yaml
|
122
|
+
- spec/examples/unicode_examples.yaml
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- spec/unicode_titlecase_spec.rb
|