nytimes-style 0.1.0 → 0.2.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/README.rdoc +1 -1
- data/index.html +27 -4
- data/lib/nytimes-style.rb +19 -3
- data/lib/nytimes-style/version.rb +1 -1
- data/test/test_nytimes_style.rb +6 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= nytimes-style
|
2
2
|
|
3
|
-
Helper methods for generating text that conforms to
|
3
|
+
Helper methods for generating text that conforms to <em>The New York Times Manual of Style and Usage</em>.
|
4
4
|
|
5
5
|
Annotated source code: http://ascheink.github.com/nytimes-style
|
6
6
|
|
data/index.html
CHANGED
@@ -33,11 +33,13 @@
|
|
33
33
|
<div class="pilwrap">
|
34
34
|
<a class="pilcrow" href="#section-2">¶</a>
|
35
35
|
</div>
|
36
|
-
<p>
|
36
|
+
<p>A small set of helper methods for generating text that conforms to <em>The New York Times Manual of Style and Usage</em>,
|
37
|
+
written by <a href="https://andreischeinkman.com">Andrei Scheinkman</a> and hosted on <a href="https://github.com/ascheink/nytimes-style">Github</a>.</p>
|
37
38
|
</td>
|
38
39
|
<td class=code>
|
39
40
|
<div class='highlight'><pre><span class="k">module</span> <span class="nn">Nytimes</span>
|
40
|
-
<span class="k">module</span> <span class="nn">Style</span
|
41
|
+
<span class="k">module</span> <span class="nn">Style</span>
|
42
|
+
</pre></div>
|
41
43
|
</td>
|
42
44
|
</tr>
|
43
45
|
<tr id='section-3'>
|
@@ -45,6 +47,27 @@
|
|
45
47
|
<div class="pilwrap">
|
46
48
|
<a class="pilcrow" href="#section-3">¶</a>
|
47
49
|
</div>
|
50
|
+
<blockquote><p>“In general, spell out the first nine cardinal and
|
51
|
+
ordinal numbers [but] spell any number that begins a sentence…”
|
52
|
+
There are many exceptions to this rule including “ages of people
|
53
|
+
and animals,” “sums of money,” “degrees of temperature” and “mentions of the Twelve
|
54
|
+
Apostles and the Ten Commandments.”</p></blockquote>
|
55
|
+
</td>
|
56
|
+
<td class=code>
|
57
|
+
<div class='highlight'><pre> <span class="k">def</span> <span class="nf">nytimes_number</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
|
58
|
+
<span class="k">if</span> <span class="n">n</span> <span class="o"><</span> <span class="mi">10</span>
|
59
|
+
<span class="sx">%w(one two three four five six seven eight nine ten)</span><span class="o">[</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="o">]</span>
|
60
|
+
<span class="k">else</span>
|
61
|
+
<span class="n">n</span><span class="o">.</span><span class="n">to_s</span>
|
62
|
+
<span class="k">end</span>
|
63
|
+
<span class="k">end</span></pre></div>
|
64
|
+
</td>
|
65
|
+
</tr>
|
66
|
+
<tr id='section-4'>
|
67
|
+
<td class=docs>
|
68
|
+
<div class="pilwrap">
|
69
|
+
<a class="pilcrow" href="#section-4">¶</a>
|
70
|
+
</div>
|
48
71
|
<blockquote><p>“Abbreviate the names of months from August through
|
49
72
|
February in news copy when they are followed by numerals: Aug. 1; Sept.
|
50
73
|
2; Oct. 3; Nov. 4; Dec. 5; Jan. 6; Feb. 7. Do not abbreviate March,
|
@@ -65,10 +88,10 @@ April, May, June and July except as a last resort in a chart or table.”</p
|
|
65
88
|
<span class="k">end</span></pre></div>
|
66
89
|
</td>
|
67
90
|
</tr>
|
68
|
-
<tr id='section-
|
91
|
+
<tr id='section-5'>
|
69
92
|
<td class=docs>
|
70
93
|
<div class="pilwrap">
|
71
|
-
<a class="pilcrow" href="#section-
|
94
|
+
<a class="pilcrow" href="#section-5">¶</a>
|
72
95
|
</div>
|
73
96
|
<blockquote><p>“The abbreviation to be used for each state, after the names of cities,
|
74
97
|
towns and counties… Use no
|
data/lib/nytimes-style.rb
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
#
|
4
|
+
# A small set of helper methods for generating text that conforms to _The New York Times Manual of Style and Usage_,
|
5
|
+
# written by [Andrei Scheinkman](https://andreischeinkman.com) and hosted on [Github](https://github.com/ascheink/nytimes-style).
|
5
6
|
module Nytimes
|
6
7
|
module Style
|
8
|
+
|
9
|
+
# > "In general, spell out the first nine cardinal and
|
10
|
+
# > ordinal numbers [but] spell any number that begins a sentence..."
|
11
|
+
# There are many exceptions to this rule including "ages of people
|
12
|
+
# and animals," "sums of money," "degrees of temperature" and "mentions of the Twelve
|
13
|
+
# Apostles and the Ten Commandments."
|
14
|
+
def nytimes_number(n)
|
15
|
+
if n < 10
|
16
|
+
%w(one two three four five six seven eight nine ten)[n - 1]
|
17
|
+
else
|
18
|
+
n.to_s
|
19
|
+
end
|
20
|
+
end
|
7
21
|
|
8
22
|
# > "Abbreviate the names of months from August through
|
9
23
|
# > February in news copy when they are followed by numerals: Aug. 1; Sept.
|
10
24
|
# > 2; Oct. 3; Nov. 4; Dec. 5; Jan. 6; Feb. 7. Do not abbreviate March,
|
11
25
|
# > April, May, June and July except as a last resort in a chart or table."
|
12
|
-
def nytimes_date(date)
|
13
|
-
|
26
|
+
def nytimes_date(date, opts={})
|
27
|
+
str = ""
|
28
|
+
str << date.strftime('%A, ') if opts[:day_of_week]
|
29
|
+
str << "#{nytimes_month_and_day date}, #{date.year}"
|
14
30
|
end
|
15
31
|
|
16
32
|
def nytimes_month_and_day(date)
|
data/test/test_nytimes_style.rb
CHANGED
@@ -7,6 +7,7 @@ class NytimesStyleTest < Test::Unit::TestCase
|
|
7
7
|
date = Date.civil(2001, 9, 11)
|
8
8
|
assert_equal nytimes_month_and_day(date), "Sept. 11"
|
9
9
|
assert_equal nytimes_date(date), "Sept. 11, 2001"
|
10
|
+
assert_equal nytimes_date(date, :day_of_week => true), "Tuesday, Sept. 11, 2001"
|
10
11
|
assert_raise(ArgumentError) { nytimes_month(0) }
|
11
12
|
end
|
12
13
|
|
@@ -16,4 +17,9 @@ class NytimesStyleTest < Test::Unit::TestCase
|
|
16
17
|
assert_raise(ArgumentError) { nytimes_state_abbrev('Canada') }
|
17
18
|
end
|
18
19
|
|
20
|
+
def test_numbers
|
21
|
+
assert_equal nytimes_number(5), 'five'
|
22
|
+
assert_equal nytimes_number(12), '12'
|
23
|
+
end
|
24
|
+
|
19
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nytimes-style
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrei Scheinkman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|