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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcc2cf8878aed212d39404deb09a9a7aecd400b7aaac9d4ace956f7d077157e6
4
- data.tar.gz: 15c1643fafce3c7f4f6dd4c449a9002282d60efe103e6209482f5e8f430a25b6
3
+ metadata.gz: 32bdc186909295c1e2ad5cfdd8eee6117da7918831b2a3ea05afe9e1a6f63a4c
4
+ data.tar.gz: 5b7241e4613c6fd6532bfeb555baf9ed77056dc2db31c0094097a5ca028f8efd
5
5
  SHA512:
6
- metadata.gz: 0a018d8e1a8801fa482a7cb96e0ecdb8bc2a3c1ab28818e5e20baa0bccae9b1a6623763cabadfa034c2abd06d902f9084a15c38c7041fc8b5ad642a1f1fd3270
7
- data.tar.gz: 50965da9de6680e9198e02b2e66ca971739382eab334f67406b68648069e40454ba2fc04bf510623ff88bc24431e032009c4310063aed573cd3c3639f6a03d30
6
+ metadata.gz: 9553d9dafa7ce0d972cc2f2841c3871870f608656238026c5af19e403504da6313dad83bdc7248cb4a09c9d5f3faaf8e0050cbcce785f877223f480a75f7ed42
7
+ data.tar.gz: 56deabb8806002538e7e36f536b7748a3f4cb7fd9a306c0364ccc3ef96bf68baabe0ffae52080bd790123de639f1f8332105d2686c3969cf7e5015f71416d453
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clamped (0.1.0)
4
+ clamped (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clamped
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
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: 0.1.0
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-07-21 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec