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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/lib/pred.rb +9 -3
  4. data/lib/pred/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5512db6a131d69919db2723534c455d9d24dcd17
4
- data.tar.gz: 7909c40ef0a5038aa0f4e4d158cbcc7fae24c3d4
3
+ metadata.gz: 7d3419c5eedeff5d9c272d6357af7b1ff359ebd6
4
+ data.tar.gz: f43d14cf230e70bbf6b8abc6220189ffe838781d
5
5
  SHA512:
6
- metadata.gz: 3520b85d17989e4a6f99df6555e2c4c4dc2142e3c01e6dc2b3fe13cd35f1d2b5642f70bd65c8723d57595bea8e86dca3f835dbbba24fe0f4ab6d00e04df28a5a
7
- data.tar.gz: a5083e4f3704021cbb29569c7cd6d528f6e3b6f09e4159a3b9ac97684f150e056a09ff607265acbd4dd53670c04a1ca7a5e9e2cd147785012f6104aee715470f
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. See the code below to see why:
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
@@ -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
- return true unless decrements?(str[0..-2])
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
- return str[0..-2] + dec(str[-1]) if lone_bottom?(str)
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
@@ -1,3 +1,3 @@
1
1
  module Pred
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin