nytimes-style 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nytimes-style.rb +11 -11
- data/lib/nytimes-style/states.yml +4 -0
- data/lib/nytimes-style/version.rb +1 -1
- data/test/test_nytimes_style.rb +13 -7
- metadata +32 -22
- checksums.yaml +0 -7
data/lib/nytimes-style.rb
CHANGED
@@ -5,11 +5,11 @@ require 'yaml'
|
|
5
5
|
# hosted on [Github](https://github.com/ascheink/nytimes-style).
|
6
6
|
module Nytimes
|
7
7
|
module Style
|
8
|
-
|
9
|
-
# > "In general, spell out the first nine cardinal and
|
8
|
+
|
9
|
+
# > "In general, spell out the first nine cardinal and
|
10
10
|
# > ordinal numbers [but] spell any number that begins a sentence..."
|
11
|
-
# Exceptions include "ages of people
|
12
|
-
# and animals," "sums of money," "degrees of temperature" and "mentions of the Twelve
|
11
|
+
# Exceptions include "ages of people
|
12
|
+
# and animals," "sums of money," "degrees of temperature" and "mentions of the Twelve
|
13
13
|
# Apostles and the Ten Commandments."
|
14
14
|
def nytimes_number(n)
|
15
15
|
if n < 10
|
@@ -30,21 +30,21 @@ module Nytimes
|
|
30
30
|
str << ", #{date.year}" unless opts[:hide_current_year] && date.year == Date.today.year
|
31
31
|
return str
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def nytimes_month_and_day(date)
|
35
35
|
"#{nytimes_month date.month} #{date.day}"
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def nytimes_month(month)
|
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
|
-
|
42
|
+
|
43
43
|
# > "Use numerals in giving clock time: 10:30 a.m.; 10:30.
|
44
44
|
# > Do not use half-past 10 except in a direct quotation.
|
45
45
|
# > Also avoid the redundant 10:30 a.m. yesterday morning and Monday afternoon at 2 p.m."
|
46
46
|
def nytimes_time(time, opts={})
|
47
|
-
raise ArgumentError.new "Time or DateTime required" unless time.
|
47
|
+
raise ArgumentError.new "Time or DateTime required" unless time.is_a?(DateTime) || time.is_a?(Time)
|
48
48
|
str = ""
|
49
49
|
str << time.strftime("%l:%M").strip
|
50
50
|
str << time.strftime(" %p").sub('PM','p.m.').sub('AM','a.m.') unless opts[:hide_abbreviation]
|
@@ -61,13 +61,13 @@ module Nytimes
|
|
61
61
|
raise ArgumentError.new "Unknown postal code, state name or FIPS code: #{state_name_or_code}" unless state
|
62
62
|
state['nytimes_abbrev']
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def nytimes_state_name(state_abbrev_or_code)
|
66
66
|
state = states[state_abbrev_or_code]
|
67
67
|
raise ArgumentError.new "Unknown postal code, abbreviation or FIPS code: #{state_abbrev_or_code}" unless state
|
68
68
|
state['name']
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
private
|
72
72
|
|
73
73
|
STATE_DATA_FILE = File.join(File.dirname(__FILE__), 'nytimes-style/states.yml')
|
@@ -77,7 +77,7 @@ module Nytimes
|
|
77
77
|
h.merge({ state['postal_code'] => state, state['name'] => state, state['fips_code'] => state })
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
|
82
82
|
end
|
83
83
|
end
|
data/test/test_nytimes_style.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require './lib/nytimes-style'
|
2
2
|
|
3
|
+
|
4
|
+
class InheritedDateTime < DateTime; end
|
5
|
+
class InheritedTime < Time; end
|
6
|
+
|
3
7
|
class NytimesStyleTest < Test::Unit::TestCase
|
4
8
|
include Nytimes::Style
|
5
9
|
|
@@ -9,7 +13,7 @@ class NytimesStyleTest < Test::Unit::TestCase
|
|
9
13
|
assert_equal "Sept. 11, 2001", nytimes_date(date)
|
10
14
|
assert_raise(ArgumentError) { nytimes_month(0) }
|
11
15
|
end
|
12
|
-
|
16
|
+
|
13
17
|
def test_date_options
|
14
18
|
date = Date.civil(2001, 9, 11)
|
15
19
|
assert_equal "Tuesday, Sept. 11, 2001", nytimes_date(date, :day_of_week => true)
|
@@ -18,31 +22,33 @@ class NytimesStyleTest < Test::Unit::TestCase
|
|
18
22
|
recent_date = Date.civil(this_year, 2, 12)
|
19
23
|
assert_equal "Feb. 12", nytimes_date(recent_date, :hide_current_year => true)
|
20
24
|
end
|
21
|
-
|
25
|
+
|
22
26
|
def test_time
|
23
27
|
time = Time.local(2011, 7, 12, 14, 30, 30)
|
24
28
|
assert_equal "2:30 p.m.", nytimes_time(time)
|
25
29
|
assert_equal "2:30", nytimes_time(time, :hide_abbreviation => true)
|
26
30
|
assert_raise(ArgumentError) { nytimes_time(Date.today) }
|
31
|
+
assert_nothing_raised { nytimes_time(InheritedDateTime.new) }
|
32
|
+
assert_nothing_raised { nytimes_time(InheritedTime.new) }
|
27
33
|
end
|
28
|
-
|
34
|
+
|
29
35
|
def test_state_abbrevs
|
30
36
|
assert_equal 'Ariz.', nytimes_state_abbrev('AZ')
|
31
37
|
assert_equal 'N.H.', nytimes_state_abbrev('New Hampshire')
|
32
38
|
assert_equal 'Wis.', nytimes_state_abbrev(55)
|
33
39
|
assert_raise(ArgumentError) { nytimes_state_abbrev('Canada') }
|
34
40
|
end
|
35
|
-
|
41
|
+
|
36
42
|
def test_state_names
|
37
43
|
assert_equal 'Arizona', nytimes_state_name('AZ')
|
38
44
|
assert_equal 'New Hampshire', nytimes_state_name('New Hampshire')
|
39
45
|
assert_equal 'Wisconsin', nytimes_state_name(55)
|
40
46
|
assert_raise(ArgumentError) { nytimes_state_name(242) }
|
41
47
|
end
|
42
|
-
|
48
|
+
|
43
49
|
def test_numbers
|
44
50
|
assert_equal 'five', nytimes_number(5)
|
45
51
|
assert_equal '12', nytimes_number(12)
|
46
52
|
end
|
47
|
-
|
48
|
-
end
|
53
|
+
|
54
|
+
end
|
metadata
CHANGED
@@ -1,26 +1,32 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nytimes-style
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.0
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Andrei Scheinkman
|
8
9
|
- Tyson Evans
|
9
10
|
- Derek Willis
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
|
14
|
+
|
15
|
+
date: 2013-05-17 00:00:00 Z
|
14
16
|
dependencies: []
|
17
|
+
|
15
18
|
description: Format numbers and dates according to The New York Times Manual of Style
|
16
|
-
email:
|
19
|
+
email:
|
17
20
|
- andrei@nytimes.com
|
18
21
|
- tyson.evans@nytimes.com
|
19
22
|
- dwillis@nytimes.com
|
20
23
|
executables: []
|
24
|
+
|
21
25
|
extensions: []
|
26
|
+
|
22
27
|
extra_rdoc_files: []
|
23
|
-
|
28
|
+
|
29
|
+
files:
|
24
30
|
- .gitignore
|
25
31
|
- README.rdoc
|
26
32
|
- Rakefile
|
@@ -33,26 +39,30 @@ files:
|
|
33
39
|
- test/test_nytimes_style.rb
|
34
40
|
homepage: http://github.com/ascheink/nytimes-style
|
35
41
|
licenses: []
|
36
|
-
|
42
|
+
|
37
43
|
post_install_message:
|
38
44
|
rdoc_options: []
|
39
|
-
|
45
|
+
|
46
|
+
require_paths:
|
40
47
|
- lib
|
41
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
51
60
|
requirements: []
|
61
|
+
|
52
62
|
rubyforge_project:
|
53
|
-
rubygems_version:
|
63
|
+
rubygems_version: 1.8.5
|
54
64
|
signing_key:
|
55
|
-
specification_version:
|
65
|
+
specification_version: 3
|
56
66
|
summary: New York Times style
|
57
|
-
test_files:
|
67
|
+
test_files:
|
58
68
|
- test/test_nytimes_style.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: d67b63a72e3be7cea0a78c9f14c5eb80a81de678
|
4
|
-
data.tar.gz: c03fce233caa03365e035c779fcb390ae61c63ab
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: e8aa049e66431b3cadca8f5d9cf2b408687a67c94d35964bb67ea9ecd7a7acd0f58b8a9910cfae36c790689a60bbd8fe01538d65f9783e1db5fc2bb64012bce5
|
7
|
-
data.tar.gz: bd48ab48f850f70bf99a0c26acf8ffd3b92bd1a5d6e5180649e7f2474c8f830d11734f796ebc6481f3d0ee9e0ecbd11efdb4add9945ddb4f098972f8625f061d
|