primitive_wrapper 1.0.1 → 2.0.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
  SHA1:
3
- metadata.gz: 4c61db086f4cde65ecab2dbb325a3a2ba6b54354
4
- data.tar.gz: 5fdce0cf8b22b2c4a25b681c4920426767cdd684
3
+ metadata.gz: de77195e3edaeb4ddf58d6e33c1fd88b26e9fc69
4
+ data.tar.gz: 5c1dc0e6730a024aa6953ba29e7333185349a2ab
5
5
  SHA512:
6
- metadata.gz: fc16390601b8af96ced06a0138f1ace2f3a9256a1cd12d395015583c78efe67498e582410951fae9c4fef692340a7f6018b69b659c485328064573b350f43b96
7
- data.tar.gz: 53077599d9802d07811b45521131757c44f120fc0cf8b4c540cb6676d29769854efa3dbf869df9c5f3c78403aa9986385cabb00a29539327de7ef778c19a9d91
6
+ metadata.gz: 26ea44e1849e51f79624f1294131bf60f1df83274408b9375293ca3877dc56d3ce93b0d725f3587a6b62b1508fc21cae4e90e3e768da96beee1daa3697e90c46
7
+ data.tar.gz: d17ed816653cc2a496279238ef5ef95cdf3ee537b464e0ef06d7ceec437f786641e7544a8f0fb3cd91aa6f78387499838c637a1f3cbdc4f8ecacdf91374b952a
data/README.md CHANGED
@@ -78,15 +78,17 @@ Also note the new method `#type_of` which allows us test the inner-most entity.
78
78
 
79
79
  #### Object methods added
80
80
 
81
- There are five new instance methods added to the base Object class necessary to implement this system.
81
+ There are six instance methods added to the base Object class necessary to implement this system.
82
82
  The most important method is the `#to_wrapper` method.
83
83
  When an instance variable calls this method, one of the wrapper containers will generate a new instance.
84
84
  The one that gets picked is the one best suited for usability.
85
85
  We also have a test method called `#wrapped?` to see if we are dealing with the original entity or its thinly wrapped sibling.
86
86
  Another method named `#prim_value` will return the inner container value or simply return `self` if it is not a container derived from the `Value` class.
87
87
  This is mostly used internally by the container objects. Now that we have wrapped versions of the base elemental objects,
88
- we need a type checking method that can work on both wrapped and unwrapped primitives: called `#type_of?`.
89
- Also needed is a method that can duplicated a primitive or its wrapped version; this is called `#pw_copy` which works like dup.
88
+ we need a type checking method that can work on both wrapped and unwrapped primitives: called `#type_of?`;
89
+ this works like `#kind_of?` but instead works on the inner-most element (if `Value` derived type).
90
+ Also, `#type` gets the effective class and evaluates as `#prim_value.class`.
91
+ Also needed is a method that can duplicate a primitive or its wrapped version; this is called `#pw_copy` which works like dup.
90
92
  Note that you can't call `#dup` on an Integer without raising an exception.
91
93
 
92
94
  Below shows which objects get mapped to which containers:
@@ -170,7 +172,8 @@ The Value class has the following instance methods:
170
172
  :to_wrapper # returns self ... prevents wrapping a wrapped entity
171
173
  :wrapped? # also on object, tests for wrapped behavior
172
174
  :type_of? # also added to object, tests innermost entity or self if primitive
173
- :inspect # string representing wrapped primitive
175
+ :type # returns the class of the wrapped primitive or self if primitive
176
+ :inspect # string representing wrapped primitive
174
177
  ```
175
178
 
176
179
  #### Bool class container
@@ -571,6 +574,11 @@ This can be mostly a matter of taste, but we can choose custom names that convey
571
574
  So it is left to you to decide.
572
575
 
573
576
  ## Revision History
577
+ ### Version 2.0.0
578
+ * fixed Range reversals defined with excluded end
579
+ * added #type to Object, Value
580
+ * added #simple? to Range, XRange
581
+
574
582
  ### Version 1.0.1
575
583
  * updated documentation to include undocumented methods
576
584
  * fixed XArray `#delete_at` bugs
@@ -10,6 +10,9 @@ class Object
10
10
  def type_of?(cls)
11
11
  kind_of? cls
12
12
  end
13
+ def type
14
+ self.class
15
+ end
13
16
  def pw_copy
14
17
  self.dup rescue self
15
18
  end
@@ -80,16 +83,20 @@ class Range # if it makes sense, add methods here
80
83
  end
81
84
  def reverse
82
85
  if exclude_end?
83
- (last...first)
86
+ if (first==last)
87
+ (last...first)
88
+ else
89
+ ((last.pred)..first)
90
+ end
84
91
  else
85
92
  (last..first)
86
93
  end
87
94
  end
88
95
  def reorder
89
96
  if exclude_end?
90
- last < first ? (last...first) : (first...last)
97
+ last < first ? reverse : (first...last)
91
98
  else
92
- last < first ? (last..first) : (first..last)
99
+ last < first ? reverse : (first..last)
93
100
  end
94
101
  end
95
102
  def reversed?
@@ -102,6 +109,16 @@ class Range # if it makes sense, add methods here
102
109
  end
103
110
  return (first..last)
104
111
  end
112
+ def element_class
113
+ return first.class
114
+ end
115
+ def simple?
116
+ return true if first.type_of? Integer
117
+ if first.type_of? String
118
+ return true if first.length==1
119
+ end
120
+ false
121
+ end
105
122
  end
106
123
 
107
124
  class Array
@@ -139,15 +156,21 @@ class Value
139
156
  def to_wrapper
140
157
  self
141
158
  end
159
+
142
160
  def wrapped?
143
161
  true
144
162
  end
163
+
145
164
  def type_of?(cls)
146
165
  return true if @value.kind_of? cls
147
166
  return true if self.kind_of? cls
148
167
  false
149
168
  end
150
169
 
170
+ def type
171
+ @value.class
172
+ end
173
+
151
174
  def ensure_valid(obj, mess = "Incompatible type")
152
175
  unless valid_type(obj)
153
176
  raise mess
@@ -165,7 +188,7 @@ class Value
165
188
  def ~
166
189
  @value
167
190
  end
168
-
191
+
169
192
  def val=(dat)
170
193
  replace(dat)
171
194
  end
@@ -708,15 +731,14 @@ class XRange < ValueAdd
708
731
  def reverse
709
732
  @value.reverse.to_xr
710
733
  end
711
- def simplify!
712
- @value = @value.simplify
713
- self
714
- end
715
734
  def reorder!
716
735
  @value = @value.reorder
717
736
  self
718
737
  end
719
-
738
+ def simplify!
739
+ @value = @value.simplify
740
+ self
741
+ end
720
742
  def simplify
721
743
  @value.simplify.to_xr
722
744
  end
@@ -1,3 +1,7 @@
1
+ # note: be sure to check if reverse handles ... and ..
2
+ # note that there is no exclude start, so reversing will require recalculation or simplification
3
+ # ... put this on the back burner for now
4
+
1
5
  module PrimitiveWrapper
2
- VERSION = "1.0.1"
6
+ VERSION = "2.0.0"
3
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primitive_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-12 00:00:00.000000000 Z
11
+ date: 2018-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blockify