augmented 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd88ac261436008274986613fc7ce91c1874b454b380e295f7acc5a43831e223
4
- data.tar.gz: 77826a1b98d4b243c87b646941c164601f628a03ceee802ab2e44acb982c7894
3
+ metadata.gz: 6d65d68527ff708f00861bd8c107acfde5f7ce813ab5a3f6b88a8d9c12a331ad
4
+ data.tar.gz: 2d1c9fe2af451feb5c9eda30aee3514304e4ba62e0baf0d38475a3093389a4d4
5
5
  SHA512:
6
- metadata.gz: 87e68662e972f392fca81ad431f2a7b7c712ae25eb28ba251a2663e2aa89d1f2223bac2d5962426c0d6dde6aadf14347b5c7664ea0150691c8e2634075c701e0
7
- data.tar.gz: 73e6fb575d524ccde9a3a545334a2159b961d07430d042aefcb114dcfbb7e06c3b7ba5776a94d3c1a7f1669971f4f335a7c6a365e91c3bd5f459000d2c504ad2
6
+ metadata.gz: 907238de8dda6ab6a1403a43ea31bdc3c7a7315d3c951a62434da1bc91ff932df1111e141ffdef65fd12d7d447c67151d3745e823ba2bbdceeff246f0bea57cf
7
+ data.tar.gz: 8ab148a0c46b387f722041efd2a73aeff7c02e3e939ff1e1edf92c013ab935a08b5c8928bc4becf238f56307e0e7b6099d04b9be64408ba18ed25297577ed21c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.7] - 2021-06-26
4
+
5
+ - Added `String#squish` and `String#squish!`.
6
+ - Added `Object#in?`.
7
+
3
8
  ## [0.2.6] - 2021-06-23
4
9
 
5
10
  - Fixed `String#blank?` not working on Ruby 2.3.
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.
@@ -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
@@ -0,0 +1,13 @@
1
+ module Augmented
2
+ module Objects
3
+ module In
4
+ refine Object do
5
+
6
+ def in? collection
7
+ collection.include?(self)
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,9 +1,11 @@
1
1
  require 'augmented/strings/blank'
2
+ require 'augmented/strings/squish'
2
3
  require 'augmented/strings/truncatable'
3
4
 
4
5
  module Augmented
5
6
  module Strings
6
7
  include Blank
8
+ include Squish
7
9
  include Truncatable
8
10
  end
9
11
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Augmented
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
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.6
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-23 00:00:00.000000000 Z
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.0.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.