modular_tree 0.3.0 → 0.4.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: a7ec15f5d6c64bba85a09321d1fcb7c1a22cd91fea24b1db49a2217a4dc73f08
4
- data.tar.gz: '08cf720767c7c907e3b7d8007125fafe5a8b51abe8701d4d0a0c5d5736df5ccd'
3
+ metadata.gz: 6fec58fa42f91715e9a59438b1bf403976618ead4f433d70b39c8458c9396fe5
4
+ data.tar.gz: 255a5d2ae6daaf623f5f6adfa7d9b7206a66e3f9613a11f061e9c2336feec943
5
5
  SHA512:
6
- metadata.gz: 171988f0d2150f15a555d035fa7833e53b64784fcbbf3a4d5c3c4dc7ab352ce3aa816dee8a281c802bb236f57951112e0c1b18e451ad62b001e26f66340c3beb
7
- data.tar.gz: 23cefa409742a9926b83fb9f1f7aecdae78b78905d7ed765c1f4fdc0044730594d1ffda4ef806c513856b75ac40ba4d788f16c13312521d333d9a73ec0be036f
6
+ metadata.gz: 74f3701071758d0fce55d9e103142532e760c861c96b2ca2835894b4c2e298f2a1190e4901db36dfcb5aa8cdfadb73ea976aad38551d58a452c1d1b0d8dc09e0
7
+ data.tar.gz: 21785c97fe07687be2c55eb1e3f5c7c9377db855392eeaa9caa490621512ef0ba930202eb63a0b0b8d50a45e6f854217955b2eeb3db4044264bcc978da821319
@@ -89,9 +89,8 @@ module Tree
89
89
 
90
90
  # Enumerator of edges in the tree. Edges are [previous-matching-node,
91
91
  # matching-node] tuples. Top-level nodes have previous-matching-node set to
92
- # nil
93
- #
94
- # FIXME: Not working right now. Not sure how #edges relates to #pairs
92
+ # nil. If the filter matches all nodes the value is an edge-representation
93
+ # of the tree
95
94
  def edges(*filter, this: true, &block)
96
95
  if block_given?
97
96
  each(*filter, this: this) { |node, _, parent| yield parent, node }
@@ -100,6 +99,19 @@ module Tree
100
99
  end
101
100
  end
102
101
 
102
+ # Return array of [previous-matching-node, matching-node] tuples. Returns
103
+ # the empty array ff there is no matching set of nodes
104
+ def pairs(first_matcher_expr, second_matcher_expr, this: true)
105
+ first_matcher = Matcher.new(first_matcher_expr)
106
+ second_matcher = Matcher.new(second_matcher_expr)
107
+ or_matcher = first_matcher | second_matcher # avoids re-computing this value over and over
108
+ result = []
109
+ nodes(first_matcher, false, this: this) { |node|
110
+ node.do_pairs(result, first_matcher, or_matcher)
111
+ }
112
+ result
113
+ end
114
+
103
115
  # Find nodes matching +filter+ and call +traverse_block+ with a node and a
104
116
  # block argument. +traverse_block+ can recurse into children by calling the
105
117
  # supplied inner block
@@ -117,18 +129,6 @@ module Tree
117
129
  nodes(filter, this: this).map { |node| traverse_block.call(node, inner_block) }
118
130
  end
119
131
 
120
- # Return array of [previous-matching-node, matching-node] tuples
121
- def pairs(first_matcher_expr, second_matcher_expr, this: true)
122
- first_matcher = Matcher.new(first_matcher_expr)
123
- second_matcher = Matcher.new(second_matcher_expr)
124
- or_matcher = first_matcher | second_matcher # avoids re-computing this value over and over
125
- result = []
126
- nodes(first_matcher, false, this: this) { |node|
127
- node.do_pairs(result, first_matcher, or_matcher)
128
- }
129
- result
130
- end
131
-
132
132
  # Traverse the tree top-down while accumulating information in an
133
133
  # accumulator object. The block takes a [accumulator, node] tuple and is
134
134
  # responsible for adding itself to the accumulator. The return value from
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen