nytimes-style 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,10 @@ Annotated source code: http://ascheink.github.com/nytimes-style
17
17
  # => "May 12, 2011"
18
18
 
19
19
  >> nytimes_date Date.today, :hide_current_year => true, :day_of_week => true
20
- # => "Wednesday, June 15"
20
+ # => "Wednesday, June 15"
21
+
22
+ >> nytimes_time Time.now, :hide_abbreviation => false
23
+ # => "2:30 p.m."
21
24
 
22
25
  >> nytimes_state_abbrev 'AZ'
23
26
  # => "Ariz."
@@ -25,6 +28,8 @@ Annotated source code: http://ascheink.github.com/nytimes-style
25
28
  >> nytimes_state_name '55'
26
29
  # => "Wisconsin"
27
30
 
28
- == AUTHOR
31
+ == AUTHORS
32
+
33
+ Andrei Scheinkman, andreischeinkman@gmail.com
29
34
 
30
- Andrei Scheinkman, andrei@nytimes.com
35
+ Tyson Evans, tyson.evans@nytimes.com
data/Rakefile CHANGED
@@ -16,12 +16,12 @@ namespace :gem do
16
16
  desc 'Build and install the gem'
17
17
  task :install do
18
18
  sh "gem build nytimes-style.gemspec"
19
- sh "sudo gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
19
+ sh "gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
20
20
  end
21
21
 
22
22
  desc 'Uninstall the jammit gem'
23
23
  task :uninstall do
24
- sh "sudo gem uninstall -x nytimes-style"
24
+ sh "gem uninstall -x nytimes-style"
25
25
  end
26
26
 
27
27
  end
data/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
5
  <title>nytimes-style.rb</title>
6
- <link rel="stylesheet" href="http://github.com/jashkenas/docco/raw/0.3.0/resources/docco.css">
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
7
  </head>
8
8
  <body>
9
9
  <div id='container'>
@@ -89,7 +89,8 @@ April, May, June and July except as a last resort in a chart or table.&rdquo;</p
89
89
  <span class="k">def</span> <span class="nf">nytimes_month</span><span class="p">(</span><span class="n">month</span><span class="p">)</span>
90
90
  <span class="k">raise</span> <span class="no">ArgumentError</span><span class="o">.</span><span class="n">new</span> <span class="s2">&quot;Unknown month: </span><span class="si">#{</span><span class="n">month</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">unless</span> <span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="mi">12</span><span class="p">)</span><span class="o">.</span><span class="n">include?</span> <span class="n">month</span>
91
91
  <span class="sx">%w(Jan. Feb. March April May June July Aug. Sept. Oct. Nov. Dec.)</span><span class="o">[</span><span class="n">month</span> <span class="o">-</span> <span class="mi">1</span><span class="o">]</span>
92
- <span class="k">end</span></pre></div>
92
+ <span class="k">end</span>
93
+ </pre></div>
93
94
  </td>
94
95
  </tr>
95
96
  <tr id='section-5'>
@@ -97,6 +98,25 @@ April, May, June and July except as a last resort in a chart or table.&rdquo;</p
97
98
  <div class="pilwrap">
98
99
  <a class="pilcrow" href="#section-5">&#182;</a>
99
100
  </div>
101
+ <blockquote><p>&ldquo;Use numerals in giving clock time: 10:30 a.m.; 10:30.
102
+ Do not use half-past 10 except in a direct quotation.
103
+ Also avoid the redundant 10:30 a.m. yesterday morning and Monday afternoon at 2 p.m.&rdquo;</p></blockquote>
104
+ </td>
105
+ <td class=code>
106
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">nytimes_time</span><span class="p">(</span><span class="n">time</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="p">{})</span>
107
+ <span class="k">raise</span> <span class="no">ArgumentError</span><span class="o">.</span><span class="n">new</span> <span class="s2">&quot;Time or DateTime required&quot;</span> <span class="k">unless</span> <span class="n">time</span><span class="o">.</span><span class="n">class</span> <span class="o">==</span> <span class="no">DateTime</span> <span class="o">||</span> <span class="n">time</span><span class="o">.</span><span class="n">class</span> <span class="o">==</span> <span class="no">Time</span>
108
+ <span class="n">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
109
+ <span class="n">str</span> <span class="o">&lt;&lt;</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%l:%M&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span>
110
+ <span class="n">str</span> <span class="o">&lt;&lt;</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot; %p&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">&#39;PM&#39;</span><span class="p">,</span><span class="s1">&#39;p.m.&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">&#39;AM&#39;</span><span class="p">,</span><span class="s1">&#39;a.m.&#39;</span><span class="p">)</span> <span class="k">unless</span> <span class="n">opts</span><span class="o">[</span><span class="ss">:hide_abbreviation</span><span class="o">]</span>
111
+ <span class="n">str</span>
112
+ <span class="k">end</span></pre></div>
113
+ </td>
114
+ </tr>
115
+ <tr id='section-6'>
116
+ <td class=docs>
117
+ <div class="pilwrap">
118
+ <a class="pilcrow" href="#section-6">&#182;</a>
119
+ </div>
100
120
  <blockquote><p>&ldquo;The abbreviation to be used for each state, after the names of cities,
101
121
  towns and counties&hellip; Use no
102
122
  spaces between initials like N.H. Do not abbreviate Alaska, Hawaii, Idaho,
@@ -39,6 +39,17 @@ module Nytimes
39
39
  raise ArgumentError.new "Unknown month: #{month}" unless (1..12).include? month
40
40
  %w(Jan. Feb. March April May June July Aug. Sept. Oct. Nov. Dec.)[month - 1]
41
41
  end
42
+
43
+ # > "Use numerals in giving clock time: 10:30 a.m.; 10:30.
44
+ # > Do not use half-past 10 except in a direct quotation.
45
+ # > Also avoid the redundant 10:30 a.m. yesterday morning and Monday afternoon at 2 p.m."
46
+ def nytimes_time(time, opts={})
47
+ raise ArgumentError.new "Time or DateTime required" unless time.class == DateTime || time.class == Time
48
+ str = ""
49
+ str << time.strftime("%l:%M").strip
50
+ str << time.strftime(" %p").sub('PM','p.m.').sub('AM','a.m.') unless opts[:hide_abbreviation]
51
+ str
52
+ end
42
53
 
43
54
  # > "The abbreviation to be used for each state, after the names of cities,
44
55
  # > towns and counties&hellip; Use no
@@ -1,5 +1,5 @@
1
1
  module Nytimes
2
2
  module Style
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "nytimes-style"
7
7
  s.version = Nytimes::Style::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Andrei Scheinkman"]
10
- s.email = ["andrei@nytimes.com"]
9
+ s.authors = ["Andrei Scheinkman", "Tyson Evans"]
10
+ s.email = ["andrei@nytimes.com", "tyson.evans@nytimes.com"]
11
11
  s.homepage = "http://github.com/ascheink/nytimes-style"
12
12
  s.summary = %q{New York Times style}
13
13
  s.description = %q{Format numbers and dates according to The New York Times Manual of Style}
@@ -19,6 +19,13 @@ class NytimesStyleTest < Test::Unit::TestCase
19
19
  assert_equal "Feb. 12", nytimes_date(recent_date, :hide_current_year => true)
20
20
  end
21
21
 
22
+ def test_time
23
+ time = Time.local(2011, 7, 12, 14, 30, 30)
24
+ assert_equal "2:30 p.m.", nytimes_time(time)
25
+ assert_equal "2:30", nytimes_time(time, :hide_abbreviation => true)
26
+ assert_raise(ArgumentError) { nytimes_time(Date.today) }
27
+ end
28
+
22
29
  def test_state_abbrevs
23
30
  assert_equal 'Ariz.', nytimes_state_abbrev('AZ')
24
31
  assert_equal 'N.H.', nytimes_state_abbrev('New Hampshire')
metadata CHANGED
@@ -1,26 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nytimes-style
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
5
+ version: 0.5.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Andrei Scheinkman
9
+ - Tyson Evans
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-06-15 00:00:00 Z
14
+ date: 2011-07-13 00:00:00 Z
19
15
  dependencies: []
20
16
 
21
17
  description: Format numbers and dates according to The New York Times Manual of Style
22
18
  email:
23
19
  - andrei@nytimes.com
20
+ - tyson.evans@nytimes.com
24
21
  executables: []
25
22
 
26
23
  extensions: []
@@ -50,18 +47,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
47
  requirements:
51
48
  - - ">="
52
49
  - !ruby/object:Gem::Version
53
- hash: 3
54
- segments:
55
- - 0
56
50
  version: "0"
57
51
  required_rubygems_version: !ruby/object:Gem::Requirement
58
52
  none: false
59
53
  requirements:
60
54
  - - ">="
61
55
  - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
56
  version: "0"
66
57
  requirements: []
67
58