open_string 0.0.2 → 0.0.3
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 +8 -8
- data/lib/open_string.rb +27 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWJmZDIwN2Y0NTM2ZTViNjc3ZGJjZDQ3ZmFmYzcwMzQ1OTcxM2QwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjIyYWJkNzBmNTUyYmU5NGM0MzY2ZTg1ODA5NzhkOTJmNTJiNGMxYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjVjMGM0M2QwOGY1OGJmZDBjMDg4ZGQ3NjVjZjgxNGQ1MzEwNzg1YzJjZGUx
|
10
|
+
Yzg0OTA2MjRmOTEzMzEzODY0Yzc2NTA1OTcxNjY0ZTFlZDQzNDNmMzY5Mjgz
|
11
|
+
OWZhMGY1MzkwNGJkMjdjZmRmODcxZmE4YzFkNGQ5YjRlMGZmNzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDc4MzMyMTU4MGMxNzc5ZTUzNjdjZGNlMjYxMmFjN2Q4MzNlYWEzOTdmNjAz
|
14
|
+
OTdlMGJkNjE1ZmFjM2Y0ZjE4MjJlZDE1YzBhYjM0ZGM3M2FmZDE1YmFlMmRj
|
15
|
+
N2UxMzc3ZDE4NTRmMmZkNjI3YTQ1YzhlMjg1MjE1OGJlNzAwNmQ=
|
data/lib/open_string.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
# Public: Provides extension methods for the built-in String class.
|
4
4
|
module OpenString
|
5
5
|
# Public: Determines if self has the same sequence of characters as evaluated
|
6
|
-
# from index 0 to self.length and from self.length to 0
|
6
|
+
# from index 0 to self.length and from self.length to 0. This ignores
|
7
|
+
# whitespace and casing.
|
7
8
|
#
|
8
9
|
# Returns true iff self contains the same sequence of characters forwards as
|
9
10
|
# it does backwards.
|
10
11
|
def palindrome?
|
11
|
-
|
12
|
+
gsub(/\s+/, '').casecmp(reverse.gsub(/\s+/, '')) == 0
|
12
13
|
end
|
13
14
|
|
14
15
|
# Methods meant to be members of the String class need to go in here. The
|
@@ -47,10 +48,34 @@ module OpenString
|
|
47
48
|
Array.new(length) { charsets.flatten.sample }.join
|
48
49
|
end
|
49
50
|
end
|
51
|
+
|
52
|
+
# Defines sets of characters such as lowercase.
|
53
|
+
module CharacterSets
|
54
|
+
def self.lowercase
|
55
|
+
%w( a b c d e f g h i j k l m n o p q r s t u v w x y z )
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.uppercase
|
59
|
+
%w( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.numbers
|
63
|
+
%w( 0 1 2 3 4 5 6 7 8 9 )
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.specials
|
67
|
+
%w{ ~ ! @ # $ % ^ & * ( ) - _ = + [ ] < > ; : ' " , . ? \ | / }
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.all
|
71
|
+
lowercase + uppercase + numbers + specials
|
72
|
+
end
|
73
|
+
end
|
50
74
|
end
|
51
75
|
|
52
76
|
# Public: Mixing OpenString extensions into String.
|
53
77
|
class String
|
54
78
|
include OpenString
|
55
79
|
extend OpenString::ClassMethods
|
80
|
+
extend OpenString::CharacterSets
|
56
81
|
end
|