xf 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62d3af5779614c09634b6f1e53a0507832f1cddc051693f8ccda36fd29cf1862
4
- data.tar.gz: 357c3a4807a9e5edb5d82c02ed06be8acd25d7e8e5e3224caeb8d67c2a4ad27d
3
+ metadata.gz: 7b22d8834efc5ccf08dbe6de45136a10b852a88028ba851c74e7f0156fbc451d
4
+ data.tar.gz: de850927d2c583eed59712be6a9d9c7e5b8f00ef43cb2091938a4138b877f905
5
5
  SHA512:
6
- metadata.gz: c76a5dea28717e733bb1938000fe5efaff5ceb8178f6b46b66d86916bcc1217274cafc05cd6bca3cc0f1986b60f1f93524c18dee29748ad8deea1c74a22ebe35
7
- data.tar.gz: 44657cd1c09fbd8e624ebcaf807dfc1c705b4434d8bc51084ff735a59b677eb7cc5785188fa7788b6d5d79f7673a3e3b75151b2334cabf765825c954dc89426c
6
+ metadata.gz: 9067391391eae8e1501fd9cc760865d659bc78624ab6e3c4f671790a1a6ffce05e11396ffaf547eb73006a0a6b71b1507a999ef5130d8824d3230b5add00d463
7
+ data.tar.gz: d6b465abbf9480e19b5c206071a49a9f127cc8e9c8dd737a5a72329c989f42653a9d6755355f333f58a4cb1d545de9c0ccc36dc472d6198f7e13f963d5705be5
data/README.md CHANGED
@@ -6,6 +6,18 @@
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/905faea654f9e0a1f811/test_coverage)](https://codeclimate.com/github/baweaver/xf/test_coverage)
7
7
  [![Build Status](https://travis-ci.org/baweaver/xf.svg?branch=master)](https://travis-ci.org/baweaver/xf)
8
8
 
9
+ ![Xf Lemur logo](img/xf_logo.png)
10
+
11
+ Xf - Short for Xform or Transform Functions meant to manipulate
12
+ Enumerables, namely deep Hashes.
13
+
14
+ ## Articles
15
+
16
+ ### How it was made
17
+
18
+ * [Xf Part One - Scopes](https://medium.com/@baweaver/on-dealing-with-deep-hashes-in-ruby-xf-part-one-scopes-f63447d59ee1)
19
+ * [Xf Part Two - Traces](https://medium.com/@baweaver/on-dealing-with-deep-hashes-in-ruby-xf-part-two-traces-23b52546a753)
20
+
9
21
  <!-- Tocer[start]: Auto-generated, don't remove. -->
10
22
 
11
23
  ## Table of Contents
@@ -12,7 +12,7 @@ module Xf
12
12
  end
13
13
 
14
14
  def self.version
15
- "0.1.0"
15
+ "0.1.1"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -133,6 +133,10 @@ module Xf
133
133
  }
134
134
  end
135
135
 
136
+ def slice(*keys)
137
+ Proc.new { |hash| hash.slice(*keys) }
138
+ end
139
+
136
140
  # Solely meant as a tap addendum
137
141
  #
138
142
  # @return [Proc[Any] -> nil]
@@ -17,8 +17,8 @@ module Xf
17
17
  # Gets a value from a Hash
18
18
  #
19
19
  # @return [type] [description]
20
- def get
21
- method(:get_value)
20
+ def get(&fn)
21
+ Proc.new { |hash| get_value(hash, &fn) }
22
22
  end
23
23
 
24
24
  # Sets a value in a Hash
@@ -54,8 +54,10 @@ module Xf
54
54
  # @param hash [Hash] Hash to get value from
55
55
  #
56
56
  # @return [Any]
57
- def get_value(hash)
58
- hash.dig(*@paths)
57
+ def get_value(hash, &fn)
58
+ value = hash.dig(*@paths)
59
+
60
+ block_given? ? fn[value] : value
59
61
  end
60
62
 
61
63
  # Sets a value at the bottom of a path without mutating the original.
@@ -20,14 +20,24 @@ module Xf
20
20
  @trace_path = trace_path
21
21
  end
22
22
 
23
- def get
24
- Proc.new { |target| get_value(target) }
23
+ # Gets a value from a Hash
24
+ #
25
+ # @param &fn [Proc]
26
+ # Block to yield the hash, key, and value from any matching element
27
+ # into. Used to transform returned values upon retrieval
28
+ #
29
+ # @return [Proc[Hash] -> Array]
30
+ # Array containing matching values, optionally transformed
31
+ def get(&fn)
32
+ Proc.new { |target| get_value(target, &fn) }
25
33
  end
26
34
 
27
- def get_value(hash)
35
+ def get_value(hash, &fn)
28
36
  retrieved_values = []
29
37
 
30
- recursing_dive(hash) { |h, k, v| retrieved_values.push(v) }
38
+ recursing_dive(hash) { |h, k, v|
39
+ retrieved_values.push(block_given? ? fn[h, k, v] : v)
40
+ }
31
41
 
32
42
  retrieved_values
33
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-22 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemsmith