powertools 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +7 -0
- data/README.md +75 -0
- data/lib/powertool/set.rb +7 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bcd41100572beb93a11d58824fc071ea5fdf680fc56f0b5c747d5233a4e73fd
|
4
|
+
data.tar.gz: 52fe1e4acd2de1331c214e2a2575e6d94672172e459303b93fe528daa4ce79ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a63ab6c525bf83c21a6d6374bf720b389c88483fa6e9620b97ed2faf033fbd68b077f8f1d42b4a97754818fb837844eded29ea197a5e83ba283fc9cf04d3a1ee
|
7
|
+
data.tar.gz: 42d65c8ab48f60abbcb0604a2604ff7221df1d4bd12dd1e96b7d680c2e2e68c2f90662c2ecfe140f81ff2aab5ed879cae694683660ba51e0bfe927df3fe0c678
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2021 C.J.Kinniburgh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Powertools
|
2
|
+
|
3
|
+
This gem provides some extensions to Ruby classes that make my life a lot easier.
|
4
|
+
|
5
|
+
It doesn't aim to be a comprehensive list of improvements, but rather a curated
|
6
|
+
list of things I find myself encountering frequently.
|
7
|
+
|
8
|
+
# Usage
|
9
|
+
|
10
|
+
Install Powertools with `gem install powertools`.
|
11
|
+
|
12
|
+
Then, you can add `require 'powertools'` to your Ruby file to access all the
|
13
|
+
features provided by Powertools.
|
14
|
+
|
15
|
+
You may also want to only use certain features.
|
16
|
+
|
17
|
+
You can currently also use the following to selectively add features:
|
18
|
+
|
19
|
+
- `require 'powertool/maybe_chain'`
|
20
|
+
- `require 'powertool/range'`
|
21
|
+
- `require 'powertool/set'`
|
22
|
+
|
23
|
+
# Warning about Breaking Changes
|
24
|
+
|
25
|
+
Some features may introduce breaking changes to the Ruby standard library.
|
26
|
+
These 'breaking changes' are generally minor changes which in my opinion
|
27
|
+
conform to my expectations about how the language should work.
|
28
|
+
|
29
|
+
Still, I'll make an effor to list any changes that break a potential assumption
|
30
|
+
about the Ruby standard library here.
|
31
|
+
|
32
|
+
## `Range#each`
|
33
|
+
|
34
|
+
If you are relying on `(4..1).each { |_| ... }` to do nothing,
|
35
|
+
because it's going from a higher number to a lower number, you should not use
|
36
|
+
the `powertool/range` package.
|
37
|
+
|
38
|
+
# Range Improvements
|
39
|
+
|
40
|
+
`#sort` is provided as a helper method to ensure your range is from smallest
|
41
|
+
to largest.
|
42
|
+
|
43
|
+
`#each` now works backwards for all classes that include a `#pred` method.
|
44
|
+
This is only enabled when a range is between two elements of the same class.
|
45
|
+
(For example, `(date.today..100000000)` is a valid Ruby range. We fallback
|
46
|
+
to the default `#each` implementation for these.)
|
47
|
+
|
48
|
+
# Maybe Chains
|
49
|
+
|
50
|
+
`#maybe_chain` is added to `Array` and `Hash`. It takes an array as an argument,
|
51
|
+
and attempts to access nested data based on the elements of the argument. If at
|
52
|
+
any point it cannot access an element, it will return nil without throwing an
|
53
|
+
error. This can be very useful for accessing deeply nested data structures, like
|
54
|
+
parsed JSON objects, which may have nil elements.
|
55
|
+
|
56
|
+
E.g.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
a = [1,2,3,{d:[9]}]
|
60
|
+
a.maybe_chain [0]
|
61
|
+
=> 1
|
62
|
+
a.maybe_chain [3]
|
63
|
+
=> {:d=>[1]}
|
64
|
+
a.maybe_chain [3, :d, 0]
|
65
|
+
=> 9
|
66
|
+
a.maybe_chain [4]
|
67
|
+
=> nil
|
68
|
+
a.maybe_chain [4, :missing_element]
|
69
|
+
=> nil
|
70
|
+
```
|
71
|
+
|
72
|
+
# Popable Sets
|
73
|
+
|
74
|
+
`#pop` has been added to `Set`. This returns a random
|
75
|
+
element from the set, and removes it from the set.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: powertools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- C. Kinniburgh
|
@@ -16,8 +16,11 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- LICENSE
|
20
|
+
- README.md
|
19
21
|
- lib/powertool/maybe_chain.rb
|
20
22
|
- lib/powertool/range.rb
|
23
|
+
- lib/powertool/set.rb
|
21
24
|
- lib/powertools.rb
|
22
25
|
homepage: http://github.com/cjkinni/powertools
|
23
26
|
licenses:
|