augmented 0.2.6 → 0.2.7
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/CHANGELOG.md +5 -0
- data/README.md +30 -0
- data/lib/augmented/objects.rb +2 -0
- data/lib/augmented/objects/in.rb +13 -0
- data/lib/augmented/strings.rb +2 -0
- data/lib/augmented/strings/squish.rb +40 -0
- data/lib/augmented/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d65d68527ff708f00861bd8c107acfde5f7ce813ab5a3f6b88a8d9c12a331ad
|
4
|
+
data.tar.gz: 2d1c9fe2af451feb5c9eda30aee3514304e4ba62e0baf0d38475a3093389a4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907238de8dda6ab6a1403a43ea31bdc3c7a7315d3c951a62434da1bc91ff932df1111e141ffdef65fd12d7d447c67151d3745e823ba2bbdceeff246f0bea57cf
|
7
|
+
data.tar.gz: 8ab148a0c46b387f722041efd2a73aeff7c02e3e939ff1e1edf92c013ab935a08b5c8928bc4becf238f56307e0e7b6099d04b9be64408ba18ed25297577ed21c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -257,6 +257,21 @@ Person.new.eat(toast.unless(toast.soggy?).else(muffin))
|
|
257
257
|
Person.new.eat(toast.unless(&:soggy?).else(muffin))
|
258
258
|
```
|
259
259
|
|
260
|
+
##### `Object#in?`
|
261
|
+
|
262
|
+
Tests if the object is included in a collection (collection must respond to `included?`).
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
using Augmented::Objects::In
|
266
|
+
|
267
|
+
2.in?([1, 2, 3])
|
268
|
+
# true
|
269
|
+
5.in?(0..2)
|
270
|
+
# false
|
271
|
+
'B'.in?('ABC')
|
272
|
+
# true
|
273
|
+
```
|
274
|
+
|
260
275
|
##### `Object#pick`
|
261
276
|
|
262
277
|
Calls a bunch of methods on an object and collects the results.
|
@@ -366,6 +381,21 @@ using Augmented::Strings::Blank
|
|
366
381
|
```
|
367
382
|
|
368
383
|
|
384
|
+
##### `String#squish`, `String#squish!`
|
385
|
+
|
386
|
+
Replaces runs of whitespace with a single space except at the edges of the string. Can be given a custom pattern and replacement.
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
using Augmented::Strings::Squish
|
390
|
+
|
391
|
+
' hello world '.squish!
|
392
|
+
# "hello world"
|
393
|
+
|
394
|
+
'---what-a-nice--kebab-'.squish(/\W+/, '_')
|
395
|
+
# "what_a_nice_kebab"
|
396
|
+
```
|
397
|
+
|
398
|
+
|
369
399
|
##### `String#truncate`, `String#truncate!`
|
370
400
|
|
371
401
|
Returns a prefix of a string up to a given number of characters.
|
data/lib/augmented/objects.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'augmented/objects/iffy'
|
2
|
+
require 'augmented/objects/in'
|
2
3
|
require 'augmented/objects/pickable'
|
3
4
|
require 'augmented/objects/tackable'
|
4
5
|
require 'augmented/objects/tappable'
|
@@ -7,6 +8,7 @@ require 'augmented/objects/thru'
|
|
7
8
|
module Augmented
|
8
9
|
module Objects
|
9
10
|
include Iffy
|
11
|
+
include In
|
10
12
|
include Pickable
|
11
13
|
include Tackable
|
12
14
|
include Tappable
|
data/lib/augmented/strings.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Augmented
|
2
|
+
module Strings
|
3
|
+
module Squish
|
4
|
+
refine String do
|
5
|
+
|
6
|
+
def squish pattern = /\s+/, replacement = ' '
|
7
|
+
dup.squish!(pattern, replacement)
|
8
|
+
end
|
9
|
+
|
10
|
+
def squish! pattern = /\s+/, replacement = ' '
|
11
|
+
cursor = 0
|
12
|
+
|
13
|
+
while match = pattern.match(self, cursor)
|
14
|
+
slice_start = match.begin(0)
|
15
|
+
slice_end = match.end(0)
|
16
|
+
slice_length = slice_end - slice_start
|
17
|
+
|
18
|
+
slice!(slice_start, slice_length)
|
19
|
+
|
20
|
+
if slice_start == 0
|
21
|
+
# we're at the start of the string
|
22
|
+
# don't insert the replacement
|
23
|
+
# don't change the cursor
|
24
|
+
elsif slice_end >= self.size
|
25
|
+
# we're at the end of the string
|
26
|
+
# don't insert the replacement
|
27
|
+
break
|
28
|
+
else
|
29
|
+
insert(slice_start, replacement)
|
30
|
+
cursor = slice_start + replacement.size
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/augmented/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: augmented
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brunze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/augmented/modules/refined.rb
|
70
70
|
- lib/augmented/objects.rb
|
71
71
|
- lib/augmented/objects/iffy.rb
|
72
|
+
- lib/augmented/objects/in.rb
|
72
73
|
- lib/augmented/objects/pickable.rb
|
73
74
|
- lib/augmented/objects/tackable.rb
|
74
75
|
- lib/augmented/objects/tappable.rb
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- lib/augmented/procs/rescuable.rb
|
79
80
|
- lib/augmented/strings.rb
|
80
81
|
- lib/augmented/strings/blank.rb
|
82
|
+
- lib/augmented/strings/squish.rb
|
81
83
|
- lib/augmented/strings/truncatable.rb
|
82
84
|
- lib/augmented/symbols.rb
|
83
85
|
- lib/augmented/symbols/arguable.rb
|
@@ -105,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
107
|
- !ruby/object:Gem::Version
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.2.21
|
109
111
|
signing_key:
|
110
112
|
specification_version: 4
|
111
113
|
summary: Useful extra methods for some Ruby core types.
|