primitive_wrapper 1.0.0 → 1.0.1
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/README.md +18 -6
- data/lib/primitive_wrapper.rb +28 -8
- data/lib/primitive_wrapper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c61db086f4cde65ecab2dbb325a3a2ba6b54354
|
4
|
+
data.tar.gz: 5fdce0cf8b22b2c4a25b681c4920426767cdd684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc16390601b8af96ced06a0138f1ace2f3a9256a1cd12d395015583c78efe67498e582410951fae9c4fef692340a7f6018b69b659c485328064573b350f43b96
|
7
|
+
data.tar.gz: 53077599d9802d07811b45521131757c44f120fc0cf8b4c540cb6676d29769854efa3dbf869df9c5f3c78403aa9986385cabb00a29539327de7ef778c19a9d91
|
data/README.md
CHANGED
@@ -434,17 +434,13 @@ Below is a list of what has changed:
|
|
434
434
|
# :each XRange ... redefined to work with descending sequences
|
435
435
|
# :reverse_each XRange ... reverse version of :each
|
436
436
|
# :re_range(ng) XRange ... creates new range converting negative start, end to positive given size==ng
|
437
|
-
#
|
437
|
+
# used by XArray access operators that use descending ranges.
|
438
438
|
```
|
439
439
|
|
440
440
|
#### XArray class container for Array with extensions
|
441
441
|
|
442
442
|
This creates a wrapped `Array` with behavior that enhances the access operators of `Array`;
|
443
|
-
additionally a few new methods were added to the wrapped version.
|
444
|
-
The methods `#ssort`, `#ssort!` sort `XArray` elements using `#to_s` on each comparison.
|
445
|
-
The methods `#isort`, `#isort!` sort `XArray` elements using `#inspect` on each comparison.
|
446
|
-
The method `#to_xa` what added to `Array` as a more terse way of creating a wrapper on `Array`.
|
447
|
-
The method `#empty!` was also added. These two aforementioned methods also get included in `XArray`.
|
443
|
+
additionally a few new methods were added to the wrapped version as well as the original `Array` class.
|
448
444
|
`XArray` mimics the behavior of `Array` but redefines `:[]` and `:[]=` to include lists wich comprise indexes, ranges, and arrays of indexes.
|
449
445
|
There is also behavior that defines many-to-one, one-to-many, and many-to-many operations. Note that one-to-one behavior has not changed.
|
450
446
|
An example best explains how this works:
|
@@ -466,6 +462,18 @@ An example best explains how this works:
|
|
466
462
|
ary[-2] = [:a, :b] # ary == [2, "c", 5, 7, "a", "b", 17, 19, :s, :s, :s, [:a, :b], [1, 2, 3]]
|
467
463
|
```
|
468
464
|
|
465
|
+
The are a few more upgrades as well as follows:
|
466
|
+
|
467
|
+
```ruby
|
468
|
+
# :to_xa Array, XArray ... Converts Array to XArray unless already an XArray
|
469
|
+
# :include? XArray ... Updated to support a list of items all of which must be included to return true
|
470
|
+
# :include_any? XArray ... true if any of the list of itmes are included
|
471
|
+
# :delete_at XArray ... enhanced version can delete a list of indexes or ranges or arrays of indexes
|
472
|
+
# returns what was deleted in the order of the list
|
473
|
+
# :ssort, :ssort! XArray ... sorts with each element called with method :to_s
|
474
|
+
# :isort, :isort! XArray ... sorts with each element called with method :inspect
|
475
|
+
```
|
476
|
+
|
469
477
|
#### Customization
|
470
478
|
|
471
479
|
Things should work out of the box, until they don't. This section will detail what customization is possible with what container.
|
@@ -563,6 +571,10 @@ This can be mostly a matter of taste, but we can choose custom names that convey
|
|
563
571
|
So it is left to you to decide.
|
564
572
|
|
565
573
|
## Revision History
|
574
|
+
### Version 1.0.1
|
575
|
+
* updated documentation to include undocumented methods
|
576
|
+
* fixed XArray `#delete_at` bugs
|
577
|
+
|
566
578
|
### Version 1.0.0
|
567
579
|
* fixed wrapper inside wrapper causing stack overflow
|
568
580
|
* Documentation updates
|
data/lib/primitive_wrapper.rb
CHANGED
@@ -1050,18 +1050,38 @@ class XArray < ValueAdd
|
|
1050
1050
|
end
|
1051
1051
|
def delete_at(*index_list)
|
1052
1052
|
return nil if index_list.empty?
|
1053
|
+
rtn = []
|
1053
1054
|
if (index_list.count==1)
|
1054
1055
|
if index_list.first==:all
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1056
|
+
rtn = @value.dup
|
1057
|
+
@value.empty!
|
1058
|
+
return rtn
|
1059
|
+
else
|
1060
|
+
ii = index_list.first
|
1061
|
+
rtn = self[ii]
|
1062
|
+
if ii.type_of? Range
|
1063
|
+
ii = ii.to_xr
|
1064
|
+
ii.re_range!(size)
|
1065
|
+
ii.reorder!
|
1066
|
+
ii.reverse_each do |idx|
|
1067
|
+
@value.delete_at(idx)
|
1068
|
+
end
|
1069
|
+
return rtn
|
1070
|
+
end
|
1062
1071
|
end
|
1063
|
-
return rtn
|
1064
1072
|
end
|
1073
|
+
rtn = self[*index_list]
|
1074
|
+
list = PrimitiveWrapper::get_list(index_list,size)
|
1075
|
+
list = list & list # remove duplicates
|
1076
|
+
list.sort.reverse.each do |idx|
|
1077
|
+
if idx.type_of? Range
|
1078
|
+
t_idx = idx.reorder
|
1079
|
+
else
|
1080
|
+
t_idx = idx
|
1081
|
+
end
|
1082
|
+
@value.delete_at(t_idx)
|
1083
|
+
end
|
1084
|
+
return rtn
|
1065
1085
|
end
|
1066
1086
|
def include?(*list) # replace with list of stuff
|
1067
1087
|
if list.count==1
|