string_splitter 0.2.0 → 0.3.0

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: fcb033c8d7804dab11a7756f3fafb06292650c048947d09b01d479e354d2dfa4
4
- data.tar.gz: ffc6e4fae751883e2f7731232ccb3b539eb95ff030d716360b284e21339651ad
3
+ metadata.gz: 128e1b2cc29cb122f3d5040f7c9e115688532c7e68c59f0a5373291e995642f9
4
+ data.tar.gz: 6b8729b7fb59aa984c1940ff0f9a1a308dded8b77c7db2b3c2a2ad4cdbd8bd52
5
5
  SHA512:
6
- metadata.gz: b6ccb81fd4b270251f0f1dc4108e67485a9795a3fd8bdb3ce852a5d7498933e0f431da0d60732fc61e9224c4676ee5104858db0e40ed6589e03eb9fa147fc0dc
7
- data.tar.gz: f4d011a2fc127645ca5bbf9fbb607d854e021021b69047a7fbdc6ba9124edbdca750901147a0cce22cd80ca05197355de94c9e3bd353b1a1a1ebfde136eefdce
6
+ metadata.gz: 3aa949fb5ac46369af379e2fd28bc18f7c93746515aea76005d606a4cb9f20426dec353bef8406264078cdccf89cdaca99902d961687f12fb72be08d9f2b0072
7
+ data.tar.gz: acd982d39a003be78b4548992cf108141e89e51a58f918e10515fb01dd1fd562db319e5c0dc5475d3e74739726e1fd752bbee4850b823705fb9520ff6b05e99f
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
+ ## 0.3.0 - 2018-06-23
2
+
3
+ - **breaking change**: rename the `default_separator` option to `default_delimiter`
4
+ - to avoid ambiguity in the code, refer to the input pattern/string as the
5
+ "delimiter" and the matched string as the "separator"
6
+
1
7
  ## 0.2.0 - 2018-06-22
2
8
 
3
- - **breaking change**: make `index` (AKA `offset`) 0-based and add `position` (AKA `pos`)
4
- as the 1-based accessor
9
+ - **breaking change**: make `index` (AKA `offset`) 0-based and add `position`
10
+ (AKA `pos`) as the 1-based accessor
5
11
 
6
12
  ## 0.1.0 - 2018-06-22
7
13
 
data/README.md CHANGED
@@ -43,15 +43,15 @@ ss.split("foo bar baz quux", " ")
43
43
  ss.split("foo bar baz quux", /\s+/)
44
44
  # => ["foo", "bar", "baz", "quux"]
45
45
 
46
- # split on the first separator
46
+ # split at the first delimiter
47
47
  ss.split("foo:bar:baz:quux", ":", at: 1)
48
48
  # => ["foo", "bar:baz:quux"]
49
49
 
50
- # split on the last separator
50
+ # split at the last delimiter
51
51
  ss.split("foo:bar:baz:quux", ":", at: -1)
52
52
  # => ["foo:bar:baz", "quux"]
53
53
 
54
- # split at multiple separator positions
54
+ # split at multiple delimiter positions
55
55
  ss.split("1:2:3:4:5:6:7:8:9", ":", at: [1..3, -2])
56
56
  # => ["1", "2", "3", "4:5:6:7", "8:9"]
57
57
 
@@ -76,11 +76,11 @@ and handle a few common cases e.g.:
76
76
  * including the separators in the results
77
77
  * removing (some) empty fields
78
78
 
79
- But, because the API is squeezed into two overloaded parameters (the separator and the limit),
79
+ But, because the API is squeezed into two overloaded parameters (the delimiter and the limit),
80
80
  achieving the desired effects can be tricky. For instance, while `String#split` removes empty
81
81
  trailing fields (by default), it provides no way to remove *all* empty fields. Likewise, the
82
82
  cramped API means there's no way to e.g. combine a limit (positive integer) with the option
83
- to preserve empty fields (negative integer), or use backreferences in a separator pattern
83
+ to preserve empty fields (negative integer), or use backreferences in a delimiter pattern
84
84
  without including its captured subexpressions in the result.
85
85
 
86
86
  If `split` was being written from scratch, without the baggage of its legacy API,
@@ -106,7 +106,7 @@ ss.split("foo:bar:baz", ":") { |split| split.position == split.count }
106
106
  # => ["foo:bar", "baz"]
107
107
  ```
108
108
 
109
- As a shortcut, the common case of splitting on separators at one or more positions is supported by an option:
109
+ As a shortcut, the common case of splitting on delimiters at one or more positions is supported by an option:
110
110
 
111
111
  ```ruby
112
112
  ss.split('foo:bar:baz:quux', ':', at: [1, -1]) # => ["foo", "bar:baz", "quux"]
@@ -116,7 +116,7 @@ ss.split('foo:bar:baz:quux', ':', at: [1, -1]) # => ["foo", "bar:baz", "quux"]
116
116
 
117
117
  I wanted to split semi-structured output into fields without having to resort to a regex or a full-blown parser.
118
118
 
119
- As an example, the nominally unstructured output of many Unix commands is often, in practice, formatted in a way
119
+ As an example, the nominally unstructured output of many Unix commands is often formatted in a way
120
120
  that's tantalizingly close to being machine-readable, apart from a few pesky exceptions e.g.:
121
121
 
122
122
  ```bash
@@ -156,7 +156,7 @@ line.match(/^(\S+) \s+ (\d+) \s+ (\S+) \s+ (\S+) \s+ (\d+) \s+ (\S+ \s+ \d+ \s+
156
156
  ```
157
157
 
158
158
  But that requires us to specify *everything*. What we really want is a version of `split`
159
- which allows us to veto splitting for the 6th and 7th separators i.e. control over which
159
+ which allows us to veto splitting for the 6th and 7th delimiters i.e. control over which
160
160
  splits are accepted, rather than being restricted to the single, baked-in strategy provided
161
161
  by the `limit` parameter.
162
162
 
@@ -179,13 +179,13 @@ ss.split(line, at: [1..5, 8])
179
179
 
180
180
  # VERSION
181
181
 
182
- 0.2.0
182
+ 0.3.0
183
183
 
184
184
  # SEE ALSO
185
185
 
186
186
  ## Gems
187
187
 
188
- - [rsplit](https://github.com/Tatzyr/rsplit) - a reverse-split implementation (only works with string separators)
188
+ - [rsplit](https://github.com/Tatzyr/rsplit) - a reverse-split implementation (only works with string delimiters)
189
189
 
190
190
  ## Articles
191
191
 
@@ -13,7 +13,7 @@ require 'values'
13
13
  # guns e.g. regex matching or parsing.
14
14
  class StringSplitter
15
15
  ACCEPT = ->(_split) { true }
16
- DEFAULT_SEPARATOR = /\s+/
16
+ DEFAULT_DELIMITER = /\s+/
17
17
  NO_SPLITS = []
18
18
 
19
19
  Split = Value.new(:captures, :count, :index, :lhs, :rhs, :separator) do
@@ -26,20 +26,20 @@ class StringSplitter
26
26
  end
27
27
 
28
28
  def initialize(
29
- default_separator: DEFAULT_SEPARATOR,
29
+ default_delimiter: DEFAULT_DELIMITER,
30
30
  include_captures: true,
31
31
  remove_empty: false,
32
32
  spread_captures: true
33
33
  )
34
- @default_separator = default_separator
34
+ @default_delimiter = default_delimiter
35
35
  @include_captures = include_captures
36
36
  @remove_empty = remove_empty
37
37
  @spread_captures = spread_captures
38
38
  end
39
39
 
40
- attr_reader :default_separator, :include_captures, :remove_empty, :spread_captures
40
+ attr_reader :default_delimiter, :include_captures, :remove_empty, :spread_captures
41
41
 
42
- def split(string, delimiter = @default_separator, at: nil, &block)
42
+ def split(string, delimiter = @default_delimiter, at: nil, &block)
43
43
  result, block, splits, count, index = split_common(string, delimiter, at, block)
44
44
 
45
45
  splits.each do |split|
@@ -67,7 +67,7 @@ class StringSplitter
67
67
 
68
68
  alias lsplit split
69
69
 
70
- def rsplit(string, delimiter = @default_separator, at: nil, &block)
70
+ def rsplit(string, delimiter = @default_delimiter, at: nil, &block)
71
71
  result, block, splits, count, index = split_common(string, delimiter, at, block)
72
72
 
73
73
  splits.reverse!.each do |split|
@@ -110,7 +110,7 @@ class StringSplitter
110
110
  # do nothing
111
111
  elsif parts.empty? # last split
112
112
  result << (!lhs.empty? ? lhs : rhs) if splits.empty?
113
- elsif !lhs.empty?
113
+ elsif rhs.empty?
114
114
  # replace the empty rhs with the non-empty lhs
115
115
  parts[0] = lhs
116
116
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StringSplitter
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_splitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chocolateboy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-22 00:00:00.000000000 Z
11
+ date: 2018-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: values