fedux_org-stdlib 0.11.11 → 0.11.12
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6156f7dfa578e610aa9eb1d9710477b14aa944b
|
4
|
+
data.tar.gz: 1e36f5e6ee58ff54b720c1b4cc3a32f3c5c32830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f260d6166372b7eabe4137dd69db0a9a20cfb5266c258a8f16723083cb7c1c26aaebc5766759ff4499017ede1c5ec5532467357009ea8c08ba6cb017af2be47a
|
7
|
+
data.tar.gz: d95f898392baeb65c6efd8322c9be31156328e18caf407c1b974a98a62014bbbba288b64c4b54437d80c863174f3f4cdb41764f7d90cda3715e5516fc6e206e7
|
data/Gemfile.lock
CHANGED
@@ -3,6 +3,27 @@
|
|
3
3
|
class Array
|
4
4
|
# Convert array to list
|
5
5
|
#
|
6
|
+
# @example Change separator for values
|
7
|
+
#
|
8
|
+
# input = %w(v1 v2 v3)
|
9
|
+
#
|
10
|
+
# input.to_list(separator: ' | '
|
11
|
+
# => "v1" | "v2" | "v3"
|
12
|
+
#
|
13
|
+
# @example Change last separator for values
|
14
|
+
#
|
15
|
+
# input = %w(v1 v2 v3)
|
16
|
+
#
|
17
|
+
# input.to_list(last_separator: ' and '
|
18
|
+
# => "v1", "v2" and "v3"
|
19
|
+
#
|
20
|
+
# @example Change character which is placed around values
|
21
|
+
#
|
22
|
+
# input = %w(v1 v2 v3)
|
23
|
+
#
|
24
|
+
# input.to_list(around: "'")
|
25
|
+
# => 'v1', 'v2', 'v3'
|
26
|
+
#
|
6
27
|
# @return [String]
|
7
28
|
# A string representation of list
|
8
29
|
def to_list(separator: ', ', last_separator: separator, around: '"')
|
@@ -5,9 +5,41 @@ require 'fedux_org_stdlib/core_ext/array/list'
|
|
5
5
|
class Hash
|
6
6
|
# Convert Hash to list
|
7
7
|
#
|
8
|
+
# For more examples see 'fedux_org_stdlib/core_ext/array/list'
|
9
|
+
#
|
10
|
+
# @example Change separator for key and value
|
11
|
+
#
|
12
|
+
# input = {
|
13
|
+
# opt1: 'asdf',
|
14
|
+
# opt2: 'asdf'
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
# input.to_list(format: "%s | %s")
|
18
|
+
# => "opt1 | asdf", "opt2 | asdf"
|
19
|
+
#
|
20
|
+
# @example Change separator between key/value-pairs
|
21
|
+
#
|
22
|
+
# input = {
|
23
|
+
# opt1: 'asdf',
|
24
|
+
# opt2: 'asdf'
|
25
|
+
# }
|
26
|
+
#
|
27
|
+
# input.to_list(format: "%s | %s")
|
28
|
+
# => "opt1 | asdf", "opt2 | asdf"
|
29
|
+
#
|
30
|
+
# @example Change character around key/value-pair
|
31
|
+
#
|
32
|
+
# input = {
|
33
|
+
# opt1: 'asdf',
|
34
|
+
# opt2: 'asdf'
|
35
|
+
# }
|
36
|
+
#
|
37
|
+
# input.to_list(around: "'")
|
38
|
+
# => 'opt1: asdf', 'opt2: asdf'
|
39
|
+
#
|
8
40
|
# @return [String]
|
9
41
|
# A string representation of hash as list
|
10
|
-
def to_list
|
11
|
-
map { |key, value| format(
|
42
|
+
def to_list(format: '%s: %s', **args)
|
43
|
+
map { |key, value| format(format, key, value) }.to_list(**args)
|
12
44
|
end
|
13
45
|
end
|
@@ -12,5 +12,23 @@ RSpec.describe Array do
|
|
12
12
|
|
13
13
|
expect(input.to_list).to eq '"opt1: asdf", "opt2: asdf"'
|
14
14
|
end
|
15
|
+
|
16
|
+
it 'passes options' do
|
17
|
+
input = {
|
18
|
+
opt1: 'asdf',
|
19
|
+
opt2: 'asdf'
|
20
|
+
}
|
21
|
+
|
22
|
+
expect(input.to_list(around: "'")).to eq %('opt1: asdf', 'opt2: asdf')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'changes format' do
|
26
|
+
input = {
|
27
|
+
opt1: 'asdf',
|
28
|
+
opt2: 'asdf'
|
29
|
+
}
|
30
|
+
|
31
|
+
expect(input.to_list(format: '%s | %s')).to eq %("opt1 | asdf", "opt2 | asdf")
|
32
|
+
end
|
15
33
|
end
|
16
34
|
end
|