clamped 0.1.0 → 1.0.1

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: 923b53ddd7893b52e35f437bc15b43fe97e824d990a7a59cf323f64a50c82085
4
+ data.tar.gz: 5b14f1cbb0b27a54621ede28d2e8c6215dd3a8ec0948eb19f42ec6251f5b5a04
5
5
  SHA512:
6
- metadata.gz: 0a018d8e1a8801fa482a7cb96e0ecdb8bc2a3c1ab28818e5e20baa0bccae9b1a6623763cabadfa034c2abd06d902f9084a15c38c7041fc8b5ad642a1f1fd3270
7
- data.tar.gz: 50965da9de6680e9198e02b2e66ca971739382eab334f67406b68648069e40454ba2fc04bf510623ff88bc24431e032009c4310063aed573cd3c3639f6a03d30
6
+ metadata.gz: a5df0bc3ae19db6955b9363b8f631bfa45ef9af761697bb0168e7eceaca1b9b536e74e5c951e3028af5ab98ac704fb40db378207cdb78a8c71c039339e1aa218
7
+ data.tar.gz: df5eb9c2e73f99a9c634ea67dbcf3e73c0e8866b6c4fc5b299d316e772175e1975ace23e13a317916587aa338649a00fb0024a6e8503be37f39e85902a71e503
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.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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/clamped.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Clamped::VERSION
8
8
  spec.authors = ["Serge Hänni"]
9
9
  spec.email = ["serge@metikular.ch"]
10
+ spec.license = "MIT"
10
11
 
11
12
  spec.summary = "Adds convenience methods to clamp values to a whitelist."
12
13
  spec.homepage = "https://github.com/metikular/clamped"
@@ -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.1"
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.1
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: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -37,6 +37,7 @@ files:
37
37
  - CHANGELOG.md
38
38
  - Gemfile
39
39
  - Gemfile.lock
40
+ - LICENSE
40
41
  - README.md
41
42
  - Rakefile
42
43
  - clamped.gemspec
@@ -48,7 +49,8 @@ files:
48
49
  - lib/clamped/version.rb
49
50
  - sig/clamped.rbs
50
51
  homepage: https://github.com/metikular/clamped
51
- licenses: []
52
+ licenses:
53
+ - MIT
52
54
  metadata:
53
55
  allowed_push_host: https://rubygems.org
54
56
  homepage_uri: https://github.com/metikular/clamped