trivet 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/lib/trivet.rb +40 -13
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08e89a9e0bf927395b3957b685542a8e9ce4971f455b1214f6fd14dc25d0c15e'
4
- data.tar.gz: 7f50bf59dbaa328abfc4dcdd1f2500a342b44430cfdfe758614917ff7ccf84c7
3
+ metadata.gz: 5fbcf1a7c9514f12a41ecaa45f4f1ba5bec3ccec08a2ea1d9c080d4d93f3e363
4
+ data.tar.gz: cf1e7334a9aa7184622c1dac9c55df342e72187390fce5d01de4772095ff91e1
5
5
  SHA512:
6
- metadata.gz: 46ecd9c3584757faec3db79f6ceee686299b597fe6666336858d03820166ce5962d36ce4c36e69808147d96f66eda01865489ea8c24336ee1770917f5b3a3ce3
7
- data.tar.gz: a1060b86507afb34f49f26f96f22e9a884e4cc6c828d92ca06162d4e15dad0c4b7b6a55e27100aaded5d5c0e85225633e508f7731e8f098aed94d56f594b48a2
6
+ metadata.gz: 8826eedd9ca3b47f572bee245675bee71629be643066151579b62dc461982f94f26e919891e53b4c258870eb5d5ce57293c647338c4ec3aa50e5e153b924240a
7
+ data.tar.gz: 6df953e0bfd143563ebfe50de94635940eb8066037f14ef5f0777e21671d9e889a2dd51fb57491c4ec34154290dbdc21118d79f279097f53bb7766da24e0157d
data/README.md CHANGED
@@ -81,19 +81,19 @@ mike@idocs.com
81
81
  <th>date</th>
82
82
  <th>notes</th>
83
83
  </tr>
84
-
84
+
85
85
  <tr>
86
86
  <td>1.0</td>
87
87
  <td>June 18, 2020</td>
88
88
  <td>Initial upload.</td>
89
89
  </tr>
90
-
90
+
91
91
  <tr>
92
92
  <td>1.1</td>
93
93
  <td>June 22, 2020</td>
94
94
  <td>Consolidated can_have_children? and can_have_child? into allow_child?.</td>
95
95
  </tr>
96
-
96
+
97
97
  <tr>
98
98
  <td>1.2</td>
99
99
  <td>January 3, 2021</td>
@@ -101,5 +101,13 @@ mike@idocs.com
101
101
  Added several methods to Trivet::Node: next_sibling, previous_sibling, have_child?, and move_child.
102
102
  </td>
103
103
  </tr>
104
+
105
+ <tr>
106
+ <td>1.3</td>
107
+ <td>January 4, 2021</td>
108
+ <td>
109
+ Renamed have_child? to have_object?. Renamed remove_child() to remove_object().
110
+ </td>
111
+ </tr>
104
112
 
105
113
  </table>
@@ -11,7 +11,7 @@ require 'lx'
11
11
  # Trivet::Node to learn about this package.
12
12
  module Trivet
13
13
  # Version
14
- VERSION = '1.2'
14
+ VERSION = '1.3'
15
15
 
16
16
  #---------------------------------------------------------------------------
17
17
  # query control constants
@@ -72,7 +72,23 @@ end
72
72
  class Trivet::Node
73
73
  # delegate
74
74
  extend Forwardable
75
- delegate %w(remove_child have_child?) => :@children
75
+
76
+ # @!method have_object?(object)
77
+ # Returns true if the node has the given object as a child. This method is
78
+ # not quite the same as include?. This method returns true only if children
79
+ # contains the actual object given, not just an object that matches `==`.
80
+ # So, for example, the following use of have_object? would return false,
81
+ # even though it cohtains a string identical to the string in @children.
82
+ #
83
+ # node.add 'whatever'
84
+ # node.include? 'whatever' # true
85
+ # node.have_object? 'whatever' # false
86
+
87
+ # @!method remove_object(object)
88
+ # Removes the given object from children. Only the exact object is removed.
89
+ # If the object is a string, strings that are identical but not that actual
90
+ # object will *not* be removed.
91
+ delegate %w(remove_object have_object?) => :@children
76
92
 
77
93
 
78
94
  #---------------------------------------------------------------------------
@@ -366,7 +382,7 @@ class Trivet::Node
366
382
  # add
367
383
  #
368
384
 
369
- # A shortcut for adding children of any arbistrary class. Takes zero or more
385
+ # A shortcut for adding children of any arbitrary class. Takes zero or more
370
386
  # params, each of which is an object.
371
387
 
372
388
  def add(*objs)
@@ -593,7 +609,7 @@ class Trivet::Node
593
609
  if @parent.is_a?(Trivet::Document)
594
610
  @parent.set_root nil, 'recurse'=>false
595
611
  elsif @parent.is_a?(Trivet::Node)
596
- @parent.remove_child self
612
+ @parent.remove_object self
597
613
  else
598
614
  raise 'unlink-unknown-parent-class: ' + @parent.class.to_
599
615
  end
@@ -1052,7 +1068,7 @@ class Trivet::Node
1052
1068
 
1053
1069
  def move_child(child, tgt)
1054
1070
  # $tm.hrm
1055
- @children.remove_child child
1071
+ @children.remove_object child
1056
1072
  tgt.add child
1057
1073
  end
1058
1074
  #
@@ -1190,12 +1206,12 @@ class Trivet::Childset
1190
1206
 
1191
1207
 
1192
1208
  #---------------------------------------------------------------------------
1193
- # remove_child
1209
+ # remove_object
1194
1210
  #
1195
1211
 
1196
1212
  # Removes the given child from the array of children. Does nothing if the
1197
1213
  # child isn't present.
1198
- def remove_child(child, opts={})
1214
+ def remove_object(child, opts={})
1199
1215
  # opts = {'recurse'=>true}.merge(opts)
1200
1216
 
1201
1217
  @children.reject!() do |el|
@@ -1216,7 +1232,7 @@ class Trivet::Childset
1216
1232
  @children.clear
1217
1233
  end
1218
1234
  #
1219
- # remove_child
1235
+ # remove_object
1220
1236
  #---------------------------------------------------------------------------
1221
1237
 
1222
1238
 
@@ -1282,7 +1298,7 @@ class Trivet::Childset
1282
1298
  # loop through all
1283
1299
  all.each do |child|
1284
1300
  bool = yield(child)
1285
- bool or remove_child(child)
1301
+ bool or remove_object(child)
1286
1302
  end
1287
1303
 
1288
1304
  # return
@@ -1307,9 +1323,20 @@ class Trivet::Childset
1307
1323
 
1308
1324
 
1309
1325
  #---------------------------------------------------------------------------
1310
- # have_child?
1326
+ # have_object?
1311
1327
  #
1312
- def have_child?(potential)
1328
+
1329
+ # Returns true if the @children contains the given object. This method is
1330
+ # not quite the same as include?. This method returns true only if @children
1331
+ # contains the actual object given, not just an object that matches ==. So,
1332
+ # for example, the following use of have_object? would return false, even
1333
+ # though it cohtains a string identical to the string in @children.
1334
+ #
1335
+ # @children.push 'whatever'
1336
+ # @children.include? 'whatever' # true
1337
+ # @children.have_object? 'whatever' # false
1338
+
1339
+ def have_object?(potential)
1313
1340
  @children.each_with_index do |child, idx|
1314
1341
  if child.equal?(potential)
1315
1342
  return idx
@@ -1319,7 +1346,7 @@ class Trivet::Childset
1319
1346
  return false
1320
1347
  end
1321
1348
  #
1322
- # have_child?
1349
+ # have_object?
1323
1350
  #---------------------------------------------------------------------------
1324
1351
 
1325
1352
 
@@ -1348,7 +1375,7 @@ class Trivet::Childset
1348
1375
 
1349
1376
  # add to children if not already there
1350
1377
  # if dup_ok or (not @children.include?(new_child))
1351
- if (not have_child?(new_child))
1378
+ if (not have_object?(new_child))
1352
1379
  # add to start of array
1353
1380
  if index == 'first'
1354
1381
  @children.unshift new_child
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trivet
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike O'Sullivan