delight 0.1.5 → 0.1.6

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: d2cd266511e6dbdfb174a5605837cf75cbebfb108b42ee5eca092c220e1ed112
4
- data.tar.gz: 41edbb872467c0fe4c83c9a376e446f24bbf9687f0df7ea99958e8d38689e237
3
+ metadata.gz: eb589267629b62a9906d523d22ecf83c034f1df0ce9bf301079891a537d9a688
4
+ data.tar.gz: 1af7bc10bb90205a4127f9aecb936b677e23d561b5a0d96e0785a181aa554ca8
5
5
  SHA512:
6
- metadata.gz: '0124922833bb99d4471f3fa968963cc70076b8529eeac5165a81f299df474b5ed13bc6a37d8e2d251ded434e2e25fb75d5f1db49b84a6882329d94faa1775fc3'
7
- data.tar.gz: 3fefc8b830592df6eafdf4b0a06af78f7bde1e40a90d60be19bac9bf52338101a651c771871ec6d1cf08ac2accc45d6c9d0fc94b3993942883fe85951e1eca7c
6
+ metadata.gz: fc015857edf6623769c2af429ae7a4308b243b24bd4ad8f6516f7ed885007280615c56119fb12bf43d3323c3d3b56c801341e492d6fbc3c092f75ecba97fb25b
7
+ data.tar.gz: bceac43c952c822ba667faa8f16157108699487f50e006add390bf4e4e059869cf1807b70bad44900db64559cf9312d90069a2704adced962484b10196170351
data/README.md CHANGED
@@ -10,7 +10,58 @@ bundle add delight
10
10
 
11
11
  ## Usage
12
12
 
13
- [...]
13
+ In order to import all available methods use the global `Delight::Enumerable` refinement.
14
+
15
+ ```ruby
16
+ class MyClass
17
+ using Delight::Enumerable
18
+
19
+ def initialize(some_list)
20
+ @some_list = some_list
21
+ end
22
+
23
+ def my_method
24
+ some_list.select_by(country: "PL")
25
+ end
26
+ end
27
+ ```
28
+
29
+ ### `.select_by`
30
+
31
+ The `.select_by` method allows you to filter an array of objects based on a
32
+ value(s) of single or multiple methods. Object in the collection must respond to
33
+ the methods you are filtering by. Calling non-existing method will raise an
34
+ `NoMethodError`.
35
+
36
+ Following two examples are equivalent:
37
+
38
+ ```ruby
39
+ addresses.select_by(country: "PL", city: "Warsaw")
40
+
41
+ addresses.select do |address|
42
+ address.country == "PL" && address.city == "Warsaw"
43
+ end
44
+ ```
45
+
46
+ Object attributes are compared using `===` operator, so you can use any object
47
+ that implements it. For example, you can use a range:
48
+
49
+ ```ruby
50
+ addresses.select_by(age: 18..)
51
+
52
+ addresses.select do |address|
53
+ address.age >= 18
54
+ end
55
+ ```
56
+
57
+ Warning, be aware of of the `===` operator behavior. For example, if you would
58
+ like to filter out the object by class, you need to use the object itself as the
59
+ argument, thus pass the `itself` method:
60
+
61
+ ```ruby
62
+ [18, 2.5, "foo"].select_by(itself: Numeric)
63
+ # => [18, 2.5]
64
+ ```
14
65
 
15
66
  ## Development
16
67
 
@@ -3,7 +3,7 @@ module Delight
3
3
  module CollectionMatcher
4
4
  def collection_matcher(element, **kwargs)
5
5
  kwargs.all? do |key, value|
6
- element.public_send(key) == value
6
+ value === element.public_send(key)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delight
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mariusz Droździel