darthjee-core_ext 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/darthjee/core_ext/array.rb +6 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/spec/lib/array_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e412855a254f3c8334a1485327c880be5bbf9c
|
4
|
+
data.tar.gz: 676209baf8fe045c8824eebad20d570881087a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7688e35d2cc25b0001e617cd484a6e6f1251bc3e5c6c5958b1662d571ad940ab2467780211fbb9609e9ace834cc37e03a6e68c029fffa571847bddb48cf8e40e
|
7
|
+
data.tar.gz: c6dbd9bc92839a16f158571599d3d1aced950f1973fb04dd0902254f82066b9b9c1fb2a4dfb869196d78cecafb7ef6e542eabe73c7464f59ddef9456e77d0fca
|
@@ -1,6 +1,12 @@
|
|
1
1
|
class Array
|
2
2
|
autoload :HashBuilder, 'darthjee/core_ext/array/hash_builder'
|
3
3
|
|
4
|
+
def mapk(*keys)
|
5
|
+
keys.inject(self) do |enum, key|
|
6
|
+
enum.map { |hash| hash[key] }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
def procedural_join(mapper = proc(&:to_s))
|
5
11
|
return '' if empty?
|
6
12
|
list = dup
|
data/spec/lib/array_spec.rb
CHANGED
@@ -3,6 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe Array do
|
4
4
|
it_behaves_like 'an array with map_to_hash method'
|
5
5
|
|
6
|
+
describe '#mapk' do
|
7
|
+
let(:array) { [{a: { b: 1 }, b: 2}, {a: { b: 3 }, b: 4}] }
|
8
|
+
|
9
|
+
it 'maps using the keys given as arguments' do
|
10
|
+
expect(array.mapk(:a, :b)).to eq([ 1, 3 ])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
describe '#procedural_join' do
|
7
15
|
let(:array) { [1, 2, -3, -4, 5] }
|
8
16
|
let(:map_proc) { proc { |v| v > 0 ? v + 1 : v - 1 } }
|