series_joiner 1.0.0 → 1.1.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 CHANGED
@@ -20,10 +20,9 @@ Add the following to your Gemfile:
20
20
 
21
21
  join_as_series() accepts the following options:
22
22
 
23
- :delimiter # inserted between items, except for the final two (default => ',')
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 => '')
25
- :conjunction # inserted between the final two items (default => 'and')
26
- :padding # inserted after delimiters, as well as before and after conjunctions (default => ' ')
25
+ :conjunction # inserted between the final two items (default => ' and ')
27
26
 
28
27
  By default, items are joined as follows:
29
28
 
@@ -37,11 +36,11 @@ By default, items are joined as follows:
37
36
 
38
37
  Here are some examples using custom delimiters and/or conjunctions:
39
38
 
40
- ['a', 'b', 'c'].join_as_series(:delimiter => ';') #=> 'a; b and c'
39
+ ['a', 'b', 'c'].join_as_series(:delimiter => '; ') #=> 'a; b and c'
41
40
 
42
- ['a', 'b', 'c'].join_as_series(:conjunction => 'or') #=> 'a, b or c'
41
+ ['a', 'b', 'c'].join_as_series(:conjunction => ' or ') #=> 'a, b or c'
43
42
 
44
- ['a', 'b', 'c'].join_as_series(:delimiter => ';', :conjunction => '; or,') #=> 'a; b; or, c'
43
+ ['a', 'b', 'c'].join_as_series(:delimiter => '; ', :conjunction => '; or,') #=> 'a; b; or, c'
45
44
 
46
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). By default, SeriesJoiner does not use the serial comma. However, the <tt>:final_delimiter</tt> option can be set to <tt>','</tt> to include it:
47
46
 
@@ -53,6 +52,13 @@ This gem is generated with jeweler and uses shoulda for testing. To run tests:
53
52
 
54
53
  rake test
55
54
 
55
+ == Notes
56
+
57
+ This gem may be compared with the Rails ActiveSupport extension to Array <tt>to_sentence()</tt> (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/conversions.rb). Here are a couple differences:
58
+ * <tt>to_sentence()</tt> requires ActiveSupport, while <tt>join_as_series</tt> has no Rails dependencies;
59
+ * <tt>to_sentence()</tt> has I18n support baken in; and,
60
+ * <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>
61
+
56
62
  == License
57
63
 
58
64
  MIT License. Copyright (c) 2011 Cerebris Corporation. See LICENSE.txt for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/series_joiner.rb CHANGED
@@ -5,13 +5,11 @@ module SeriesJoiner
5
5
  # :delimiter => inserted between items, except for the final two (default => ',')
6
6
  # :final_delimiter => inserted between the final two items (if > 2), but before the conjunction (default => '')
7
7
  # :conjunction => inserted between the final two items (default => 'and')
8
- # :padding => inserted after delimiters, as well as before and after conjunctions (default => ' ')
9
8
  #
10
9
  def join_as_series(options = {})
11
- padding = options[:padding] || ' '
12
- delimiter = options[:delimiter] || ','
10
+ delimiter = options[:delimiter] || ', '
13
11
  final_delimiter = options[:final_delimiter] || ''
14
- conjunction = options[:conjunction] || 'and'
12
+ conjunction = options[:conjunction] || ' and '
15
13
 
16
14
  sz = self.size
17
15
  if sz > 0
@@ -19,11 +17,11 @@ module SeriesJoiner
19
17
  if sz > 1
20
18
  if sz > 2
21
19
  for i in 1..(sz - 2)
22
- r += delimiter + padding + self[i]
20
+ r += delimiter + self[i]
23
21
  end
24
22
  r += final_delimiter
25
23
  end
26
- r += padding + conjunction + padding + self[sz - 1]
24
+ r += conjunction + self[sz - 1]
27
25
  end
28
26
  end
29
27
  return r
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{series_joiner}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Gebhardt"]
@@ -21,7 +21,7 @@ class TestSeriesJoiner < Test::Unit::TestCase
21
21
 
22
22
  context "using an 'or' conjunction" do
23
23
  setup do
24
- @options = {:conjunction => 'or'}
24
+ @options = {:conjunction => ' or '}
25
25
  end
26
26
 
27
27
  should "join an array of one item" do
@@ -40,7 +40,7 @@ class TestSeriesJoiner < Test::Unit::TestCase
40
40
 
41
41
  context "using a ';' delimiter" do
42
42
  setup do
43
- @options = {:delimiter => ';'}
43
+ @options = {:delimiter => '; '}
44
44
  end
45
45
 
46
46
  should "join an array of one item" do
@@ -57,41 +57,41 @@ class TestSeriesJoiner < Test::Unit::TestCase
57
57
  end
58
58
  end
59
59
 
60
- context "using a ',' final delimiter" do
60
+ context "using a ';' delimiter properly" do
61
61
  setup do
62
- @options = {:final_delimiter => ','}
62
+ @options = {:delimiter => '; ', :conjunction => '; or, '}
63
63
  end
64
64
 
65
65
  should "join an array of one item" do
66
66
  assert_equal 'a', ['a'].join_as_series(@options)
67
67
  end
68
68
  should "join an array of two items" do
69
- assert_equal 'a and b', ['a', 'b'].join_as_series(@options)
69
+ assert_equal 'a; or, b', ['a', 'b'].join_as_series(@options)
70
70
  end
71
71
  should "join an array of three items" do
72
- assert_equal 'a, b, and c', ['a', 'b', 'c'].join_as_series(@options)
72
+ assert_equal 'a; b; or, c', ['a', 'b', 'c'].join_as_series(@options)
73
73
  end
74
74
  should "join an array of four items" do
75
- assert_equal 'a, b, c, and d', ['a', 'b', 'c', 'd'].join_as_series(@options)
75
+ assert_equal 'a; b; c; or, d', ['a', 'b', 'c', 'd'].join_as_series(@options)
76
76
  end
77
77
  end
78
78
 
79
- context "acting as a straight join without any padding" do
79
+ context "using a ',' final delimiter" do
80
80
  setup do
81
- @options = {:delimiter => '/', :conjunction => '/', :padding => ''}
81
+ @options = {:final_delimiter => ','}
82
82
  end
83
83
 
84
84
  should "join an array of one item" do
85
85
  assert_equal 'a', ['a'].join_as_series(@options)
86
86
  end
87
87
  should "join an array of two items" do
88
- assert_equal 'a/b', ['a', 'b'].join_as_series(@options)
88
+ assert_equal 'a and b', ['a', 'b'].join_as_series(@options)
89
89
  end
90
90
  should "join an array of three items" do
91
- assert_equal 'a/b/c', ['a', 'b', 'c'].join_as_series(@options)
91
+ assert_equal 'a, b, and c', ['a', 'b', 'c'].join_as_series(@options)
92
92
  end
93
93
  should "join an array of four items" do
94
- assert_equal 'a/b/c/d', ['a', 'b', 'c', 'd'].join_as_series(@options)
94
+ assert_equal 'a, b, c, and d', ['a', 'b', 'c', 'd'].join_as_series(@options)
95
95
  end
96
96
  end
97
97
  end
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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Gebhardt