chars 0.1.0 → 0.1.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.
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/README.txt +9 -3
- data/TODO.txt +13 -0
- data/lib/chars/char_set.rb +17 -15
- data/lib/chars/extensions/string.rb +15 -15
- data/lib/chars/version.rb +1 -1
- data/spec/char_set_spec.rb +2 -2
- metadata +5 -3
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= Chars
|
2
2
|
|
3
3
|
* http://chars.rubyforge.org/
|
4
|
-
* http://github.com/postmodern/chars
|
4
|
+
* http://github.com/postmodern/chars/
|
5
5
|
* Postmodern (postmodern.mod3 at gmail.com)
|
6
6
|
|
7
7
|
== DESCRIPTION:
|
@@ -37,16 +37,22 @@ recognizing text and generating random text from specific character sets.
|
|
37
37
|
|
38
38
|
== EXAMPLES:
|
39
39
|
|
40
|
-
* Determine
|
40
|
+
* Determine whether a byte belongs to a character set:
|
41
41
|
|
42
42
|
0x41.alpha?
|
43
43
|
# => true
|
44
44
|
|
45
|
-
* Determine
|
45
|
+
* Determine whether a String belongs to a character set:
|
46
46
|
|
47
47
|
"22e1c0".hex?
|
48
48
|
# => true
|
49
49
|
|
50
|
+
* Find all sub-strings that belong to a character set within a String:
|
51
|
+
|
52
|
+
ls = File.read('/bin/ls')
|
53
|
+
Chars.printable.strings_in(ls)
|
54
|
+
# => ["/lib64/ld-linux-x86-64.so.2", "KIq/", "5J~!", "%L~!", ...]
|
55
|
+
|
50
56
|
* Return a random character from the set of all characters:
|
51
57
|
|
52
58
|
Chars.all.random_char
|
data/TODO.txt
ADDED
data/lib/chars/char_set.rb
CHANGED
@@ -162,7 +162,7 @@ module Chars
|
|
162
162
|
index = 0
|
163
163
|
|
164
164
|
while index <= (data.length - min_length)
|
165
|
-
if self
|
165
|
+
if self === data[index...(index + min_length)]
|
166
166
|
sub_index = (index + min_length)
|
167
167
|
|
168
168
|
while self.include_char?(data[sub_index..sub_index])
|
@@ -189,23 +189,25 @@ module Chars
|
|
189
189
|
|
190
190
|
alias + |
|
191
191
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
string.each_byte do |b|
|
203
|
-
return false unless include?(b)
|
204
|
-
end
|
192
|
+
#
|
193
|
+
# Returns +true+ if all of the bytes within the specified _string_
|
194
|
+
# are included in the character set, returns +false+ otherwise.
|
195
|
+
#
|
196
|
+
# Chars.alpha === "hello"
|
197
|
+
# # => true
|
198
|
+
#
|
199
|
+
def ===(string)
|
200
|
+
return false unless string.respond_to?(:each_byte)
|
205
201
|
|
206
|
-
|
202
|
+
string.each_byte do |b|
|
203
|
+
return false unless include?(b)
|
207
204
|
end
|
208
205
|
|
206
|
+
return true
|
207
|
+
end
|
208
|
+
|
209
|
+
alias =~ ===
|
210
|
+
|
209
211
|
#
|
210
212
|
# Inspects the character set.
|
211
213
|
#
|
@@ -3,63 +3,63 @@ require 'chars/chars'
|
|
3
3
|
class String
|
4
4
|
|
5
5
|
def numeric?
|
6
|
-
Chars::NUMERIC
|
6
|
+
Chars::NUMERIC === self
|
7
7
|
end
|
8
8
|
|
9
9
|
def octal?
|
10
|
-
Chars::OCTAL
|
10
|
+
Chars::OCTAL === self
|
11
11
|
end
|
12
12
|
|
13
13
|
def uppercase_hex?
|
14
|
-
Chars::UPPERCASE_HEXADECIMAL
|
14
|
+
Chars::UPPERCASE_HEXADECIMAL === self
|
15
15
|
end
|
16
16
|
|
17
17
|
def lowercase_hex?
|
18
|
-
Chars::LOWERCASE_HEXADECIMAL
|
18
|
+
Chars::LOWERCASE_HEXADECIMAL === self
|
19
19
|
end
|
20
20
|
|
21
21
|
def hex?
|
22
|
-
Chars::HEXADECIMAL
|
22
|
+
Chars::HEXADECIMAL === self
|
23
23
|
end
|
24
24
|
|
25
25
|
def uppercase_alpha?
|
26
|
-
Chars::UPPERCASE_ALPHA
|
26
|
+
Chars::UPPERCASE_ALPHA === self
|
27
27
|
end
|
28
28
|
|
29
29
|
def lowercase_alpha?
|
30
|
-
Chars::LOWERCASE_ALPHA
|
30
|
+
Chars::LOWERCASE_ALPHA === self
|
31
31
|
end
|
32
32
|
|
33
33
|
def alpha?
|
34
|
-
Chars::ALPHA
|
34
|
+
Chars::ALPHA === self
|
35
35
|
end
|
36
36
|
|
37
37
|
def alpha_numeric?
|
38
|
-
Chars::ALPHA_NUMERIC
|
38
|
+
Chars::ALPHA_NUMERIC === self
|
39
39
|
end
|
40
40
|
|
41
41
|
def punctuation?
|
42
|
-
Chars::PUNCTUATION
|
42
|
+
Chars::PUNCTUATION === self
|
43
43
|
end
|
44
44
|
|
45
45
|
def symbolic?
|
46
|
-
Chars::SYMBOLS
|
46
|
+
Chars::SYMBOLS === self
|
47
47
|
end
|
48
48
|
|
49
49
|
def space?
|
50
|
-
Chars::SPACE
|
50
|
+
Chars::SPACE === self
|
51
51
|
end
|
52
52
|
|
53
53
|
def printable?
|
54
|
-
Chars::PRINTABLE
|
54
|
+
Chars::PRINTABLE === self
|
55
55
|
end
|
56
56
|
|
57
57
|
def control?
|
58
|
-
Chars::CONTROL
|
58
|
+
Chars::CONTROL === self
|
59
59
|
end
|
60
60
|
|
61
61
|
def ascii?
|
62
|
-
Chars::ASCII
|
62
|
+
Chars::ASCII === self
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
data/lib/chars/version.rb
CHANGED
data/spec/char_set_spec.rb
CHANGED
@@ -180,7 +180,7 @@ describe Chars::CharSet do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should determine if a String is made up of the characters from the char set" do
|
183
|
-
(@char_set
|
184
|
-
(@char_set
|
183
|
+
(@char_set === "AABCBAA").should == true
|
184
|
+
(@char_set === "AADDEE").should_not == true
|
185
185
|
end
|
186
186
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.12.1
|
24
24
|
version:
|
25
25
|
description: Chars is a Ruby library for working with various character sets, recognizing text and generating random text from specific character sets.
|
26
26
|
email:
|
@@ -33,10 +33,12 @@ extra_rdoc_files:
|
|
33
33
|
- History.txt
|
34
34
|
- Manifest.txt
|
35
35
|
- README.txt
|
36
|
+
- TODO.txt
|
36
37
|
files:
|
37
38
|
- History.txt
|
38
39
|
- Manifest.txt
|
39
40
|
- README.txt
|
41
|
+
- TODO.txt
|
40
42
|
- Rakefile
|
41
43
|
- lib/chars.rb
|
42
44
|
- lib/chars/char_set.rb
|