joined 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 508cc1389e031ef74fd7e700066a4b7642d10db2754acc384670fce2277ea68d
4
- data.tar.gz: c69ddae19a6ddaaeb349111a5cb076f3fb75466584d98953c0c93d47d6247564
3
+ metadata.gz: 7dd36033f9acabd1327c4bbd212c9fd6c76fe3f525de7d0f7f64431ac3c97205
4
+ data.tar.gz: 9de8199c4b2b5b1d88b82f6864e839b7aba336500ea8638af2768d2e57480513
5
5
  SHA512:
6
- metadata.gz: a34b32456b37ec9fb5fcba35b64a28153b4eb76bf89e8afadec977df8f7ad9d1dbf9b4aee90b9df01d915734531355e5ed41ea5970a5cd9e70b51bd488216d06
7
- data.tar.gz: c5b39a60e832cdee4b2a1e02a16b31501bbdf0718c5fd04fef4e1b9243054e713d197203051476dc6387c5d9492d492ed8e2c3279d3d697d9b46e087fb6f41c2
6
+ metadata.gz: e98eca82e38a6a82284a17b33556d84f06aec3c7954b6e4d2a59a514352c76512933628be44e171e3e47be4870c4303e10f528daeb2dce0e197c23bf3d4fe6d3
7
+ data.tar.gz: 38298fde467ae58616c81b8daea4a9f31989a768010965613c0acb51c28f12737fd789b8388d4ee90fb75d22dba5e35c04a83c09570c3d5d2c55a3e858a3bc77
@@ -0,0 +1,19 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+ ---
4
+ # yamllint disable rule:line-length
5
+ name: typos
6
+ 'on':
7
+ push:
8
+ branches:
9
+ - master
10
+ pull_request:
11
+ branches:
12
+ - master
13
+ jobs:
14
+ typos:
15
+ timeout-minutes: 15
16
+ runs-on: ubuntu-24.04
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: crate-ci/typos@v1.32.0
data/.gitignore CHANGED
@@ -1,8 +1,9 @@
1
- *.gem
2
- .DS_Store
3
1
  .bundle/
2
+ .DS_Store
4
3
  .idea/
5
4
  .yardoc/
5
+ *.gem
6
+ .ruby-*
6
7
  coverage/
7
8
  doc/
8
9
  node_modules/
data/.rubocop.yml CHANGED
@@ -18,3 +18,4 @@ Layout/EndOfLine:
18
18
  EnforcedStyle: lf
19
19
  Style/EvalWithLocation:
20
20
  Enabled: false
21
+ require: []
data/Gemfile.lock CHANGED
@@ -10,8 +10,8 @@ GEM
10
10
  ast (2.4.3)
11
11
  builder (3.3.0)
12
12
  docile (1.4.1)
13
- json (2.11.3)
14
- language_server-protocol (3.17.0.4)
13
+ json (2.12.0)
14
+ language_server-protocol (3.17.0.5)
15
15
  lint_roller (1.1.0)
16
16
  minitest (5.25.5)
17
17
  minitest-reporters (1.7.1)
@@ -29,7 +29,7 @@ GEM
29
29
  rake (13.2.1)
30
30
  regexp_parser (2.10.0)
31
31
  rexml (3.4.1)
32
- rubocop (1.75.4)
32
+ rubocop (1.75.5)
33
33
  json (~> 2.3)
34
34
  language_server-protocol (~> 3.17.0.2)
35
35
  lint_roller (~> 1.1.0)
data/README.md CHANGED
@@ -27,6 +27,23 @@ orange, banana, and pear
27
27
 
28
28
  That's it.
29
29
 
30
+ ## Options
31
+
32
+ The `joined` method supports the following parameters:
33
+
34
+ * `words_connector` (String) (defaults to: ', ') -
35
+ the sign or word used to join all but the last element
36
+ in arrays with three or more elements.
37
+ * `last_word_connector` (String) (defaults to: ', and ') -
38
+ the sign or word used to join the last element in arrays
39
+ with three or more element.
40
+ * `oxford` (Boolean) (defaults to: true) -
41
+ should we place a comma before the `last_word_connector`?
42
+ If false, it will remove a leading comma from the `last_word_connector`,
43
+ however, it does not add a comma if one is not already specified in the `last_word_connector`.
44
+
45
+ See the [Yard docs](https://rubydoc.info/github/yegor256/joined/master/frames) for full gem documentation.
46
+
30
47
  ## How to contribute
31
48
 
32
49
  Read
data/REUSE.toml CHANGED
@@ -4,9 +4,17 @@
4
4
  version = 1
5
5
  [[annotations]]
6
6
  path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
7
11
  "**.json",
8
12
  "**.md",
13
+ "**.png",
9
14
  "**.txt",
15
+ "**/.DS_Store",
16
+ "**/.gitignore",
17
+ "**/.pdd",
10
18
  "**/*.csv",
11
19
  "**/*.jpg",
12
20
  "**/*.json",
@@ -16,15 +24,8 @@ path = [
16
24
  "**/*.svg",
17
25
  "**/*.txt",
18
26
  "**/*.vm",
19
- "**/.DS_Store",
20
- "**/.gitignore",
21
- "**/.pdd",
22
27
  "**/CNAME",
23
28
  "**/Gemfile.lock",
24
- ".DS_Store",
25
- ".gitattributes",
26
- ".gitignore",
27
- ".pdd",
28
29
  "Gemfile.lock",
29
30
  "README.md",
30
31
  "renovate.json",
data/joined.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'joined'
12
- s.version = '0.1.0'
12
+ s.version = '0.2.0'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'A simple Ruby gem that adds a .joined() method to Array'
15
15
  s.description =
data/lib/joined.rb CHANGED
@@ -12,12 +12,24 @@ class Array
12
12
  # Join strings into a single line, splitting them with comma
13
13
  # and placing "AND" between the last two items.
14
14
  #
15
- # @param [Boolean] oxford Should we place a comma before AND?
16
- # @return [String] The text generated
17
- def joined(oxford: true)
15
+ # @param [String] words_connector
16
+ # The sign or word used to join all but the last element
17
+ # in arrays with three or more elements.
18
+ # @param [String] last_word_connector
19
+ # The sign or word used to join the last element in arrays
20
+ # with three or more element.
21
+ # @param [Boolean] oxford
22
+ # Should we place a comma before the :last_word_connector?
23
+ # If false, it will remove a leading comma from the :last_word_connector,
24
+ # however it does not add a comma if one is not already specified in the :last_word_connector.
25
+ # @return [String] The text generated (with items joined)
26
+ def joined(oxford: true, words_connector: ', ', last_word_connector: ', and ')
18
27
  return '' if empty?
19
28
  return first if length == 1
20
29
 
21
- "#{self[0...-1].join(', ')}#{',' if length > 2 && oxford} and #{self[-1]}"
30
+ final_connector = (last_word_connector || '').dup
31
+ final_connector.sub!(/^,/, '') unless oxford && length > 2
32
+
33
+ "#{self[0...-1].join(words_connector)}#{final_connector}#{self[-1]}"
22
34
  end
23
35
  end
data/test/test_joined.rb CHANGED
@@ -25,4 +25,43 @@ class Testjoined < Minitest::Test
25
25
  assert_equal('apple, banana and orange', %w[apple banana orange].joined(oxford: false))
26
26
  assert_equal('apple, banana, orange and pear', %w[apple banana orange pear].joined(oxford: false))
27
27
  end
28
+
29
+ def test_with_words_connector
30
+ assert_equal('one two, and three', %w[one two three].joined(words_connector: ' '))
31
+ assert_equal('one & two, and three', %w[one two three].joined(words_connector: ' & '))
32
+ assert_equal('onetwo, and three', %w[one two three].joined(words_connector: nil))
33
+ end
34
+
35
+ def test_with_last_word_connector
36
+ assert_equal 'one, two, and also three', %w[one two three].joined(last_word_connector: ', and also ')
37
+ assert_equal 'one, two and also three', %w[one two three].joined(last_word_connector: ' and also ')
38
+ assert_equal 'one, twothree', %w[one two three].joined(last_word_connector: nil)
39
+ assert_equal 'one, two three', %w[one two three].joined(last_word_connector: ' ')
40
+ assert_equal 'one, two and three', %w[one two three].joined(last_word_connector: ' and ')
41
+ end
42
+
43
+ def test_with_last_word_connector_but_without_oxford_comma
44
+ assert_equal 'one, two and also three', %w[one two three].joined(oxford: false, last_word_connector: ', and also ')
45
+ assert_equal 'one, two and also three', %w[one two three].joined(oxford: false, last_word_connector: ' and also ')
46
+ assert_equal 'one, twothree', %w[one two three].joined(oxford: false, last_word_connector: nil)
47
+ assert_equal 'one, two three', %w[one two three].joined(oxford: false, last_word_connector: ' ')
48
+ assert_equal 'one, two and three', %w[one two three].joined(oxford: false, last_word_connector: ' and ')
49
+ end
50
+
51
+ def test_two_elements
52
+ assert_equal 'one and two', %w[one two].joined
53
+ assert_equal 'one two', %w[one two].joined(last_word_connector: ' ')
54
+ end
55
+
56
+ def test_one_element
57
+ assert_equal 'one', ['one'].joined
58
+ end
59
+
60
+ def test_with_invalid_options
61
+ exception = assert_raises ArgumentError do
62
+ %w[one two].joined(passing: 'invalid option')
63
+ end
64
+
65
+ assert_equal 'unknown keyword: :passing', exception.message
66
+ end
28
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joined
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -29,6 +29,7 @@ files:
29
29
  - ".github/workflows/pdd.yml"
30
30
  - ".github/workflows/rake.yml"
31
31
  - ".github/workflows/reuse.yml"
32
+ - ".github/workflows/typos.yml"
32
33
  - ".github/workflows/xcop.yml"
33
34
  - ".github/workflows/yamllint.yml"
34
35
  - ".gitignore"