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 +4 -4
- data/.github/workflows/typos.yml +19 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +3 -3
- data/README.md +17 -0
- data/REUSE.toml +8 -7
- data/joined.gemspec +1 -1
- data/lib/joined.rb +16 -4
- data/test/test_joined.rb +39 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd36033f9acabd1327c4bbd212c9fd6c76fe3f525de7d0f7f64431ac3c97205
|
4
|
+
data.tar.gz: 9de8199c4b2b5b1d88b82f6864e839b7aba336500ea8638af2768d2e57480513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/.rubocop.yml
CHANGED
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.
|
14
|
-
language_server-protocol (3.17.0.
|
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.
|
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.
|
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 [
|
16
|
-
#
|
17
|
-
|
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
|
-
|
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.
|
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"
|