series_joiner 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -7
- data/VERSION +1 -1
- data/lib/series_joiner.rb +18 -9
- data/series_joiner.gemspec +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= SeriesJoiner
|
2
2
|
|
3
|
-
A gem for joining items in arrays together into grammatically correct series.
|
3
|
+
A gem for joining items in arrays together into grammatically correct series, such as "a, b and c".
|
4
4
|
|
5
5
|
SeriesJoiner extends the <tt>Array</tt> class with a <tt>join_as_series()</tt> method which is similar to the built-in <tt>join()</tt> method. However, <tt>join_as_series()</tt> allows for custom delimiters and conjunctions.
|
6
6
|
|
@@ -18,7 +18,7 @@ Add the following to your Gemfile:
|
|
18
18
|
|
19
19
|
== Usage
|
20
20
|
|
21
|
-
join_as_series() accepts the following options:
|
21
|
+
<tt>join_as_series()</tt> accepts the following options:
|
22
22
|
|
23
23
|
:delimiter # inserted between items, except for the final two (default => ', ')
|
24
24
|
:final_delimiter # inserted between the final two items (if > 2), but before the conjunction (default => '')
|
@@ -42,10 +42,22 @@ Here are some examples using custom delimiters and/or conjunctions:
|
|
42
42
|
|
43
43
|
['a', 'b', 'c'].join_as_series(:delimiter => '; ', :conjunction => '; or, ') #=> 'a; b; or, c'
|
44
44
|
|
45
|
-
The use of the serial comma (i.e. the final comma sometimes used before the conjunction) is much debated in grammar (http://en.wikipedia.org/wiki/Serial_comma).
|
45
|
+
The use of the serial comma (i.e. the final comma sometimes used before the conjunction) is much debated in grammar circles (http://en.wikipedia.org/wiki/Serial_comma). And who doesn't enjoy a rousing debate about grammar? (Don't answer that)
|
46
|
+
|
47
|
+
By default, SeriesJoiner sides with The New York Times stylebook and does not use the serial comma. However, so as not to offend adherents to The Chicago Manual of Style, the <tt>:final_delimiter</tt> option can be set to <tt>','</tt> to include it. For example:
|
46
48
|
|
47
49
|
['a', 'b', 'c'].join_as_series(:final_delimiter => ',') #=> 'a, b, and c'
|
48
50
|
|
51
|
+
== I18n Support
|
52
|
+
|
53
|
+
If you're using SeriesJoiner in a project with I18n support, such as Rails, include the following translations for your locales:
|
54
|
+
|
55
|
+
en:
|
56
|
+
series_joiner:
|
57
|
+
default_delimiter: ', '
|
58
|
+
default_final_delimiter: ''
|
59
|
+
default_conjunction: ' and '
|
60
|
+
|
49
61
|
== Implementation
|
50
62
|
|
51
63
|
This gem is generated with jeweler and uses shoulda for testing. To run tests:
|
@@ -54,11 +66,10 @@ This gem is generated with jeweler and uses shoulda for testing. To run tests:
|
|
54
66
|
|
55
67
|
== Notes
|
56
68
|
|
57
|
-
This gem may be compared with the
|
69
|
+
This gem's <tt>join_as_series()</tt> method may be compared with the similar <tt>to_sentence()</tt> method implemented in ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/conversions.rb). There are several differences:
|
58
70
|
* <tt>to_sentence()</tt> requires ActiveSupport, while <tt>join_as_series</tt> has no dependencies;
|
59
|
-
* <tt>to_sentence()</tt>
|
60
|
-
* <tt>to_sentence()</tt>
|
61
|
-
* <tt>to_sentence()</tt> requires two options (<tt>:two_words_connector</tt> and <tt>:last_word_connector</tt>) to override a conjunction, instead of the one (<tt>:conjunction</tt>) required by <tt>join_as_series</tt>.
|
71
|
+
* <tt>to_sentence()</tt> implements the serial comma (see definition above) by default, while <tt>join_as_series()</tt> does not; and,
|
72
|
+
* <tt>to_sentence()</tt> requires two options (<tt>:two_words_connector</tt> and <tt>:last_word_connector</tt>) to override a conjunction, instead of the one (<tt>:conjunction</tt>) required by <tt>join_as_series()</tt>.
|
62
73
|
|
63
74
|
== License
|
64
75
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/series_joiner.rb
CHANGED
@@ -1,15 +1,24 @@
|
|
1
1
|
module SeriesJoiner
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# options:
|
5
|
-
# :delimiter => inserted between items, except for the final two (default => ',')
|
6
|
-
# :final_delimiter => inserted between the final two items (if > 2), but before the conjunction (default => '')
|
7
|
-
# :conjunction => inserted between the final two items (default => 'and')
|
2
|
+
# Joins items in an array together in a grammatically correct manner.
|
8
3
|
#
|
4
|
+
# Options:
|
5
|
+
# * <tt>delimiter</tt> - inserted between items, except for the final two (default: ', ')
|
6
|
+
# * <tt>final_delimiter</tt> - inserted between the final two items (if > 2), but before the conjunction (default: '')
|
7
|
+
# * <tt>conjunction</tt> - inserted between the final two items (default: ' and ')
|
9
8
|
def join_as_series(options = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
if defined?(I18n)
|
10
|
+
default_delimiter = I18n.translate(:'series_joiner.default_delimiter', :locale => options[:locale])
|
11
|
+
default_final_delimiter = I18n.translate(:'series_joiner.default_final_delimiter', :locale => options[:locale])
|
12
|
+
default_conjunction = I18n.translate(:'series_joiner.default_conjunction', :locale => options[:locale])
|
13
|
+
else
|
14
|
+
default_delimiter = ', '
|
15
|
+
default_final_delimiter = ''
|
16
|
+
default_conjunction = ' and '
|
17
|
+
end
|
18
|
+
|
19
|
+
delimiter = options[:delimiter] || default_delimiter
|
20
|
+
final_delimiter = options[:final_delimiter] || default_final_delimiter
|
21
|
+
conjunction = options[:conjunction] || default_conjunction
|
13
22
|
|
14
23
|
sz = self.size
|
15
24
|
if sz > 0
|
data/series_joiner.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: series_joiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dan Gebhardt
|