clamped 0.1.0 → 1.0.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -1
- data/lib/clamped/string.rb +2 -1
- data/lib/clamped/symbol.rb +2 -1
- data/lib/clamped/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32bdc186909295c1e2ad5cfdd8eee6117da7918831b2a3ea05afe9e1a6f63a4c
|
4
|
+
data.tar.gz: 5b7241e4613c6fd6532bfeb555baf9ed77056dc2db31c0094097a5ca028f8efd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9553d9dafa7ce0d972cc2f2841c3871870f608656238026c5af19e403504da6313dad83bdc7248cb4a09c9d5f3faaf8e0050cbcce785f877223f480a75f7ed42
|
7
|
+
data.tar.gz: 56deabb8806002538e7e36f536b7748a3f4cb7fd9a306c0364ccc3ef96bf68baabe0ffae52080bd790123de639f1f8332105d2686c3969cf7e5015f71416d453
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,6 +41,10 @@ Supported classes:
|
|
41
41
|
|
42
42
|
"apple".clamped(%w[apple banana])
|
43
43
|
# "apple"
|
44
|
+
|
45
|
+
|
46
|
+
"apple".clamped(%w[banana orange], default: "strawberry")
|
47
|
+
# "strawberry"
|
44
48
|
```
|
45
49
|
|
46
50
|
`strict: false` calls `to_s` on the passed array:
|
@@ -59,6 +63,10 @@ Supported classes:
|
|
59
63
|
|
60
64
|
:apple.clamped(%i[apple banana])
|
61
65
|
# :apple
|
66
|
+
|
67
|
+
|
68
|
+
:apple.clamped(%i[banana orange], default: :strawberry)
|
69
|
+
# :strawberry
|
62
70
|
```
|
63
71
|
|
64
72
|
`strict: false` calls `to_sym` on the passed array:
|
@@ -95,7 +103,7 @@ Clamp an array with another array:
|
|
95
103
|
|
96
104
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
97
105
|
|
98
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, run `bundle` to update the `Gemfile.lock`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
99
107
|
|
100
108
|
## Contributing
|
101
109
|
|
data/lib/clamped/string.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class String
|
4
|
-
def clamped(whitelist, strict: true)
|
4
|
+
def clamped(whitelist, strict: true, default: nil)
|
5
5
|
is_included = proc do |item|
|
6
6
|
if strict
|
7
7
|
item == self
|
@@ -11,5 +11,6 @@ class String
|
|
11
11
|
end
|
12
12
|
|
13
13
|
return self if whitelist.any?(is_included)
|
14
|
+
default
|
14
15
|
end
|
15
16
|
end
|
data/lib/clamped/symbol.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Symbol
|
4
|
-
def clamped(whitelist, strict: true)
|
4
|
+
def clamped(whitelist, strict: true, default: nil)
|
5
5
|
is_included = proc do |item|
|
6
6
|
if strict
|
7
7
|
item == self
|
@@ -11,5 +11,6 @@ class Symbol
|
|
11
11
|
end
|
12
12
|
|
13
13
|
return self if whitelist.any?(is_included)
|
14
|
+
default
|
14
15
|
end
|
15
16
|
end
|
data/lib/clamped/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clamped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serge Hänni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|