pred 0.1.1 → 0.1.2
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 +6 -1
- data/lib/pred.rb +9 -3
- data/lib/pred/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: 7d3419c5eedeff5d9c272d6357af7b1ff359ebd6
|
|
4
|
+
data.tar.gz: f43d14cf230e70bbf6b8abc6220189ffe838781d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b64a2886ec2eb65060a91c01315a7222f5e64b932c02066759337553380fe4f1823b0ae09bddaaed7c7fd9a9b86801771cdd45aef9a70794ef52d60fbe3e712b
|
|
7
|
+
data.tar.gz: 1c090f974a599a1163a889f93e1393518d2f47dade49ce0e121c3a5ea1e9477cdf55ea65c3794b9bd51bc71d2490db7d6e4d0c9f85e6fa2751c8e12ac2568f6b
|
data/README.md
CHANGED
|
@@ -29,7 +29,8 @@ Or install it yourself as:
|
|
|
29
29
|
This method updates String, Integer, and Symbol to include `#pred` as one of its instance methods.
|
|
30
30
|
The `#pred` method is simply the inverse of `#succ`. The method `#pred!` is implemented only on `String` due to its mutating abilities.
|
|
31
31
|
Integer is trivial, but String is a mother bear. There are many tricky edge cases on how `#succ`
|
|
32
|
-
works, and finding an inverse operation proved harder than first glance.
|
|
32
|
+
works, and finding an inverse operation proved harder than first glance.
|
|
33
|
+
See the code below to see why:
|
|
33
34
|
|
|
34
35
|
```ruby
|
|
35
36
|
"az".succ # "ba"
|
|
@@ -45,11 +46,15 @@ works, and finding an inverse operation proved harder than first glance. See the
|
|
|
45
46
|
"`".succ # "a" ... edge case "a".pred should equal "`"
|
|
46
47
|
```
|
|
47
48
|
|
|
49
|
+
There are even edge cases like: `t_string.succ == '!a!'` where `t_string` does not exist.
|
|
50
|
+
Normal use should not run into such cases however.
|
|
51
|
+
|
|
48
52
|
Now we have a balance of force in the ruby universe as `#pred` is the ying of the yang `#succ`.
|
|
49
53
|
The name `pred` is shorthand for predecessor as `succ` is shorthand for successor.
|
|
50
54
|
If you create the method `#succ` on one of your classes, you should also create its counterpart `#pred`.
|
|
51
55
|
|
|
52
56
|
## Revision History
|
|
57
|
+
* Version 0.1.2 fixed bug on edge case '!a!.pred
|
|
53
58
|
* Version 0.1.1 fixed bug on edge case 'a'.pred
|
|
54
59
|
|
|
55
60
|
## Development
|
data/lib/pred.rb
CHANGED
|
@@ -77,13 +77,17 @@ module Pred
|
|
|
77
77
|
return false
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def self.lone_bottom?(str) # 'a'.pred etc broken
|
|
80
|
+
def self.lone_bottom?(str, fix=[]) # 'a'.pred etc broken
|
|
81
|
+
fix[0]=str.dup
|
|
81
82
|
while !letter_digit?(str[-1])
|
|
82
83
|
str = str[0..-2]
|
|
83
84
|
return false if str.empty?
|
|
84
85
|
end
|
|
85
86
|
if "aA0".include? str[-1]
|
|
86
|
-
|
|
87
|
+
unless decrements?(str[0..-2])
|
|
88
|
+
fix[0][str.length-1] = dec(str[-1])
|
|
89
|
+
return true
|
|
90
|
+
end
|
|
87
91
|
end
|
|
88
92
|
return false
|
|
89
93
|
end
|
|
@@ -184,7 +188,9 @@ module Pred
|
|
|
184
188
|
return "" if str.ord==0
|
|
185
189
|
end
|
|
186
190
|
return str[0..-2] + dec(str[-1]) unless decrements?(str)
|
|
187
|
-
|
|
191
|
+
if lone_bottom?(str,rtn=[])
|
|
192
|
+
return rtn.first
|
|
193
|
+
end
|
|
188
194
|
return rcur_decrement_string(str, ref, str.length-1)
|
|
189
195
|
end
|
|
190
196
|
end
|
data/lib/pred/version.rb
CHANGED