public
Description: A Ruby port of John Gruber's TitleCase Perl script
Homepage:
Clone URL: git://github.com/samaaron/titlecase-rb.git
titlecase-rb / title_tester.rb
100755 68 lines (47 sloc) 1.546 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby -wKU
require 'open3'
 
original_titles = <<END
Q&A With Steve Jobs: 'That's What Happens In Technology'
What Is AT&T's Problem?
Apple Deal With AT&T Falls Through
 
this v that
this vs that
this v. that
this vs. that
 
The SEC's Apple Probe: What You Need to Know
 
'by the Way, small word at the start but within quotes.'
 
Small word at end is nothing to be afraid of
 
 
Starting Sub-Phrase With a Small Word: a Trick, Perhaps?
Sub-Phrase With a Small Word in Quotes: 'a Trick, Perhaps?'
Sub-Phrase With a Small Word in Quotes: "a Trick, Perhaps?"
 
"Nothing to Be Afraid of?"
"Nothing to Be Afraid Of?"
 
a thing
END
 
perl_title_case_output = <<END
Q&A With Steve Jobs: 'That's What Happens in Technology'
What Is AT&T's Problem?
Apple Deal With AT&T Falls Through
 
This v That
This vs That
This v. That
This vs. That
 
The SEC's Apple Probe: What You Need to Know
 
'By the Way, Small Word at the Start but Within Quotes.'
 
Small Word at End Is Nothing to Be Afraid Of
 
 
Starting Sub-Phrase With a Small Word: A Trick, Perhaps?
Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'
Sub-Phrase With a Small Word in Quotes: "A Trick, Perhaps?"
 
"Nothing to Be Afraid Of?"
"Nothing to Be Afraid Of?"
 
A Thing
END
 
ruby_title_case_output = ""
 
Open3.popen3('./title_case.rb') do |stdin, stdout, stderr|
  stdin.puts original_titles
  stdin.close
  ruby_title_case_output = stdout.readlines.join
end
 
puts perl_title_case_output
puts ruby_title_case_output
puts "Versions match? #{perl_title_case_output == ruby_title_case_output}"