joined 0.0.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db52755ef87faa3e9cad4394811ca4305108bceeb3b3456852c49a7f13af87cb
4
- data.tar.gz: 789ca4420f0a0d461306c95478efda9665a3617ea8ba41d47beb147c6b5868e4
3
+ metadata.gz: 508cc1389e031ef74fd7e700066a4b7642d10db2754acc384670fce2277ea68d
4
+ data.tar.gz: c69ddae19a6ddaaeb349111a5cb076f3fb75466584d98953c0c93d47d6247564
5
5
  SHA512:
6
- metadata.gz: 3c2049dde1dc54630b03c71b2456034cc19cd3cc819ff11f88ceaa29f0015e77951ed9ceea4a5be7353f342f1583ba00d5896f13e2fb0b1d8c17af59c2b75533
7
- data.tar.gz: 8caec01188aa49976f89ea3afbfbdcae7a7945d695711b44e1a7b3126c37a5a810898784cf6f4e421346afeb281e723752dafab01d4977d584b9281216102594
6
+ metadata.gz: a34b32456b37ec9fb5fcba35b64a28153b4eb76bf89e8afadec977df8f7ad9d1dbf9b4aee90b9df01d915734531355e5ed41ea5970a5cd9e70b51bd488216d06
7
+ data.tar.gz: c5b39a60e832cdee4b2a1e02a16b31501bbdf0718c5fd04fef4e1b9243054e713d197203051476dc6387c5d9492d492ed8e2c3279d3d697d9b46e087fb6f41c2
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/joined)](https://hitsofcode.com/view/github/yegor256/joined)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/joined/blob/master/LICENSE.txt)
13
13
 
14
- Maybe you know [`to_sentence`][to_sentence] from Rails.
14
+ Do you know [`to_sentence`][to_sentence] from Rails?
15
15
  This gem does exactly the same, but without Rails.
16
16
 
17
17
  ```ruby
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.0.1'
12
+ s.version = '0.1.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
@@ -9,10 +9,15 @@
9
9
  # Copyright:: Copyright (c) 2025 Yegor Bugayenko
10
10
  # License:: MIT
11
11
  class Array
12
- def joined
12
+ # Join strings into a single line, splitting them with comma
13
+ # and placing "AND" between the last two items.
14
+ #
15
+ # @param [Boolean] oxford Should we place a comma before AND?
16
+ # @return [String] The text generated
17
+ def joined(oxford: true)
13
18
  return '' if empty?
14
19
  return first if length == 1
15
20
 
16
- "#{self[0...-1].join(', ')}#{',' if length > 2} and #{self[-1]}"
21
+ "#{self[0...-1].join(', ')}#{',' if length > 2 && oxford} and #{self[-1]}"
17
22
  end
18
23
  end
data/test/test_joined.rb CHANGED
@@ -17,4 +17,12 @@ class Testjoined < Minitest::Test
17
17
  assert_equal('apple, banana, and orange', %w[apple banana orange].joined)
18
18
  assert_equal('apple, banana, orange, and pear', %w[apple banana orange pear].joined)
19
19
  end
20
+
21
+ def test_without_oxford_comma
22
+ assert_equal('', [].joined(oxford: false))
23
+ assert_equal('apple', ['apple'].joined(oxford: false))
24
+ assert_equal('apple and banana', %w[apple banana].joined(oxford: false))
25
+ assert_equal('apple, banana and orange', %w[apple banana orange].joined(oxford: false))
26
+ assert_equal('apple, banana, orange and pear', %w[apple banana orange pear].joined(oxford: false))
27
+ end
20
28
  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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko