series_joiner 1.2.2 → 1.2.3

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Cerebris Corporation
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # SeriesJoiner [![Build Status](https://secure.travis-ci.org/cerebris/series_joiner.png)](http://travis-ci.org/cerebris/series_joiner)
2
+
3
+ A gem for joining items in arrays together into grammatically correct series, such as "a, b and c".
4
+
5
+ SeriesJoiner extends the `Array` class with a `join_as_series()` method which is similar to the built-in `join()` method. However, `join_as_series()` allows for custom delimiters and conjunctions.
6
+
7
+ ## Installation
8
+
9
+ Run the following (perhaps as sudo):
10
+
11
+ ```
12
+ gem install series_joiner
13
+ ```
14
+
15
+ ## Bundler Configuration
16
+
17
+ Add the following to your Gemfile:
18
+
19
+ ```
20
+ gem 'series_joiner'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ `join_as_series()` accepts the following options:
26
+
27
+ ```
28
+ :delimiter # inserted between items, except for the final two (default => ', ')
29
+ :final_delimiter # inserted between the final two items (if > 2), but before the conjunction (default => '')
30
+ :conjunction # inserted between the final two items (default => ' and ')
31
+ ```
32
+
33
+ By default, items are joined as follows:
34
+
35
+ ```
36
+ ['a'].join_as_series #=> 'a'
37
+
38
+ ['a', 'b'].join_as_series #=> 'a and b'
39
+
40
+ ['a', 'b', 'c'].join_as_series #=> 'a, b and c'
41
+
42
+ ['a', 'b', 'c', 'd'].join_as_series #=> 'a, b, c and d'
43
+ ```
44
+
45
+ Here are some examples using custom delimiters and/or conjunctions:
46
+
47
+ ```
48
+ ['a', 'b', 'c'].join_as_series(:delimiter => '; ') #=> 'a; b and c'
49
+
50
+ ['a', 'b', 'c'].join_as_series(:conjunction => ' or ') #=> 'a, b or c'
51
+
52
+ ['a', 'b', 'c'].join_as_series(:delimiter => '; ', :conjunction => '; or, ') #=> 'a; b; or, c'
53
+ ```
54
+
55
+ 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. Anyway, SeriesJoiner does not use the serial comma by default. If you prefer to use it, just set the `:final_delimiter` option to `','`:
56
+
57
+ ```
58
+ ['a', 'b', 'c'].join_as_series(:final_delimiter => ',') #=> 'a, b, and c'
59
+ ```
60
+
61
+ ## I18n Support
62
+
63
+ If you're using SeriesJoiner in a project with I18n support, include the following translations for your locales:
64
+
65
+ ```
66
+ en:
67
+ series_joiner:
68
+ default_delimiter: ', '
69
+ default_final_delimiter: ''
70
+ default_conjunction: ' and '
71
+ ```
72
+
73
+ ## Tests
74
+
75
+ This gem uses rspec for testing. To test:
76
+
77
+ ```
78
+ rake spec
79
+ ```
80
+
81
+ ## Notes
82
+
83
+ This gem's `join_as_series()` method may be compared with the similar `to_sentence()` method implemented in ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/conversions.rb). There are several differences:
84
+
85
+ * `to_sentence()` is part of ActiveSupport, while `join_as_series` is independent;
86
+ * `to_sentence()` implements the serial comma (see definition above) by default, while `join_as_series()` does not; and,
87
+ * `to_sentence()` requires two options (`:two_words_connector` and `:last_word_connector`) to override a conjunction, instead of the one (`:conjunction`) required by `join_as_series()`.
88
+
89
+ ## License
90
+
91
+ Copyright (c) 2011 Cerebris Corporation. This is free software released under the MIT License (see MIT-LICENSE for details).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,3 +1,3 @@
1
1
  module SeriesJoiner
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe SeriesJoiner do
4
+ describe "using default options" do
5
+ it "should join an empty array as nil" do
6
+ [].join_as_series.should eq nil
7
+ end
8
+ it "should join an array of one item" do
9
+ ['a'].join_as_series.should eq 'a'
10
+ end
11
+ it "should join an array of two items" do
12
+ ['a', 'b'].join_as_series.should eq 'a and b'
13
+ end
14
+ it "should join an array of three items" do
15
+ ['a', 'b', 'c'].join_as_series.should eq 'a, b and c'
16
+ end
17
+ it "should join an array of four items" do
18
+ ['a', 'b', 'c', 'd'].join_as_series.should eq 'a, b, c and d'
19
+ end
20
+ end
21
+
22
+ describe "using an 'or' conjunction" do
23
+ let(:options) { {:conjunction => ' or '} }
24
+
25
+ it "should join an array of one item" do
26
+ ['a'].join_as_series(options).should eq 'a'
27
+ end
28
+ it "should join an array of two items" do
29
+ ['a', 'b'].join_as_series(options).should eq 'a or b'
30
+ end
31
+ it "should join an array of three items" do
32
+ ['a', 'b', 'c'].join_as_series(options).should eq 'a, b or c'
33
+ end
34
+ it "should join an array of four items" do
35
+ ['a', 'b', 'c', 'd'].join_as_series(options).should eq 'a, b, c or d'
36
+ end
37
+ end
38
+
39
+ describe "using a ';' delimiter" do
40
+ let(:options) { {:delimiter => '; '} }
41
+
42
+ it "should join an array of one item" do
43
+ ['a'].join_as_series(options).should eq 'a'
44
+ end
45
+ it "should join an array of two items" do
46
+ ['a', 'b'].join_as_series(options).should eq 'a and b'
47
+ end
48
+ it "should join an array of three items" do
49
+ ['a', 'b', 'c'].join_as_series(options).should eq 'a; b and c'
50
+ end
51
+ it "should join an array of four items" do
52
+ ['a', 'b', 'c', 'd'].join_as_series(options).should eq 'a; b; c and d'
53
+ end
54
+ end
55
+
56
+ describe "using a ';' delimiter properly" do
57
+ let(:options) { {:delimiter => '; ', :conjunction => '; or, '} }
58
+
59
+ it "should join an array of one item" do
60
+ ['a'].join_as_series(options).should eq 'a'
61
+ end
62
+ it "should join an array of two items" do
63
+ ['a', 'b'].join_as_series(options).should eq 'a; or, b'
64
+ end
65
+ it "should join an array of three items" do
66
+ ['a', 'b', 'c'].join_as_series(options).should eq 'a; b; or, c'
67
+ end
68
+ it "should join an array of four items" do
69
+ ['a', 'b', 'c', 'd'].join_as_series(options).should eq 'a; b; c; or, d'
70
+ end
71
+ end
72
+
73
+ describe "using a ',' final delimiter" do
74
+ let(:options) { {:final_delimiter => ','} }
75
+
76
+ it "should join an array of one item" do
77
+ ['a'].join_as_series(options).should eq 'a'
78
+ end
79
+ it "should join an array of two items" do
80
+ ['a', 'b'].join_as_series(options).should eq 'a and b'
81
+ end
82
+ it "should join an array of three items" do
83
+ ['a', 'b', 'c'].join_as_series(options).should eq 'a, b, and c'
84
+ end
85
+ it "should join an array of four items" do
86
+ ['a', 'b', 'c', 'd'].join_as_series(options).should eq 'a, b, c, and d'
87
+ end
88
+ end
89
+ end
@@ -0,0 +1 @@
1
+ require 'series_joiner'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: series_joiner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000 Z
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70182283182780 !ruby/object:Gem::Requirement
16
+ requirement: &70142208065620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70182283182780
24
+ version_requirements: *70142208065620
25
25
  description: Extends Array with a join_as_series() method for joining arrays of items
26
26
  together into grammatically correct series. Useful for joining series like 'a, b
27
27
  and c'. Custom delimiters and conjunctions can be specified.
@@ -30,9 +30,14 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - lib/series_joiner.rb
34
33
  - lib/series_joiner/array_additions.rb
35
34
  - lib/series_joiner/version.rb
35
+ - lib/series_joiner.rb
36
+ - MIT-LICENSE
37
+ - Rakefile
38
+ - README.md
39
+ - spec/series_joiner_spec.rb
40
+ - spec/spec_helper.rb
36
41
  homepage: https://github.com/cerebris/series_joiner
37
42
  licenses: []
38
43
  post_install_message:
@@ -57,5 +62,7 @@ rubygems_version: 1.8.10
57
62
  signing_key:
58
63
  specification_version: 3
59
64
  summary: Join items in arrays together into grammatically correct series.
60
- test_files: []
65
+ test_files:
66
+ - spec/series_joiner_spec.rb
67
+ - spec/spec_helper.rb
61
68
  has_rdoc: