chars 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -1,3 +1,15 @@
1
+ === 0.1.2 / 2009-09-21
2
+
3
+ * Require Hoe >= 2.3.3.
4
+ * Require YARD >= 0.2.3.5.
5
+ * Require RSpec >= 1.2.8.
6
+ * Added Chars.visibile and Chars::VISIBLE (thanks flatline).
7
+ * Added CharSet#random_distinct_bytes, CharSet#random_distinct_chars,
8
+ and CharSet#random_distinct_string (thanks flatline).
9
+ * Use 'hoe/signing' for signed RubyGems.
10
+ * Moved to YARD based documentation.
11
+ * All specs now pass on JRuby 1.3.1.
12
+
1
13
  === 0.1.1 / 2009-04-01
2
14
 
3
15
  * Renamed CharSet#=~ to CharSet#===.
data/README.txt CHANGED
@@ -27,13 +27,16 @@ recognizing text and generating random text from specific character sets.
27
27
  '[', ']', '{', '}', '.', '?', '!', '@', '#', '$', '%', '^', '&', '*',
28
28
  '_', '+', '=', '|', '\\', '<', '>', '/')
29
29
  * Space (' ', '\f', '\n', '\r', '\t', '\v')
30
+ * Visible ('0' - '9', 'a' - 'z', 'A' - 'Z', '\'', '"', '`', ',',
31
+ ';', ':', '~', '-', '(', ')', '[', ']', '{', '}', '.', '?', '!', '@',
32
+ '#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',)
30
33
  * Printable ('0' - '9', 'a' - 'z', 'A' - 'Z', ' ', '\'', '"', '`', ',',
31
34
  ';', ':', '~', '-', '(', ')', '[', ']', '{', '}', '.', '?', '!', '@',
32
35
  '#', '$', '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/',
33
36
  '\f', '\n', '\r', '\t', '\v')
34
37
  * Control ('\x00' - '\x1f', '\x7f')
35
- * ASCII ('\x00' - '\x7f')
36
- * All ('\x00' - '\xff')
38
+ * Signed ASCII ('\x00' - '\x7f')
39
+ * ASCII ('\x00' - '\xff')
37
40
 
38
41
  == EXAMPLES:
39
42
 
@@ -60,9 +63,13 @@ recognizing text and generating random text from specific character sets.
60
63
 
61
64
  * Return a random Array of characters from the alpha-numeric character set:
62
65
 
63
- Chars.alpha_numeric.random_array(10)
66
+ Chars.alpha_numeric.random_chars(10)
64
67
  # => ["Q", "N", "S", "4", "x", "z", "3", "M", "F", "F"]
65
68
 
69
+ * Return a random Array of a random length of unique characters from the visible character set:
70
+ Chars.visible.random_distinct_chars(1..10)
71
+ # => ["S", "l", "o", "8", "'", "q"]
72
+
66
73
  * Return a random String from the set of all characters:
67
74
 
68
75
  Chars.all.random_string(10)
data/Rakefile CHANGED
@@ -2,13 +2,23 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
+ require 'hoe/signing'
5
6
  require './tasks/spec.rb'
6
- require './lib/chars/version.rb'
7
+ require './tasks/yard.rb'
7
8
 
8
- Hoe.new('chars', Chars::VERSION) do |p|
9
- p.rubyforge_name = 'chars'
10
- p.developer('Postmodern','postmodern.mod3@gmail.com')
11
- p.remote_rdoc_dir = '/'
9
+ Hoe.spec('chars') do
10
+ self.rubyforge_name = 'chars'
11
+ self.developer('Postmodern','postmodern.mod3@gmail.com')
12
+ self.remote_rdoc_dir = '/'
13
+ self.extra_deps = [
14
+ ['yard', '>=0.2.3.5']
15
+ ]
16
+
17
+ self.extra_dev_deps = [
18
+ ['rspec', '>=1.2.8']
19
+ ]
20
+
21
+ self.spec_extras = {:has_rdoc => 'yard'}
12
22
  end
13
23
 
14
24
  # vim: syntax=Ruby
@@ -4,7 +4,10 @@ module Chars
4
4
  class CharSet < SortedSet
5
5
 
6
6
  #
7
- # Creates a new CharSet object with the given _chars_.
7
+ # Creates a new CharSet object.
8
+ #
9
+ # @param [Array<String, Integer, Range>] chars
10
+ # The chars for the CharSet.
8
11
  #
9
12
  def initialize(*chars)
10
13
  super()
@@ -29,8 +32,14 @@ module Chars
29
32
  alias map_bytes map
30
33
 
31
34
  #
32
- # Returns +true+ if the character set includes the specified _char_,
33
- # returns +false+ otherwise.
35
+ # Determines if a character is contained within the character set.
36
+ #
37
+ # @param [String] char
38
+ # The character to search for.
39
+ #
40
+ # @return [Boolean]
41
+ # Specifies whether the character is contained within the
42
+ # character set.
34
43
  #
35
44
  def include_char?(char)
36
45
  return false unless char.respond_to?(:each_byte)
@@ -41,67 +50,125 @@ module Chars
41
50
  end
42
51
 
43
52
  #
44
- # Returns all the characters within the character set as Strings.
53
+ # The characters within the character set.
54
+ #
55
+ # @return [Array<String>]
56
+ # All the characters within the character set.
45
57
  #
46
58
  def chars
47
59
  map { |b| b.chr }
48
60
  end
49
61
 
50
62
  #
51
- # Iterates over every character within the character set, passing
52
- # each to the given _block_.
63
+ # Iterates over every character within the character set.
64
+ #
65
+ # @yield [char]
66
+ # If a block is given, it will be passed each character in the
67
+ # character set.
68
+ #
69
+ # @yieldparam [String] char
70
+ # Each character in the character set.
53
71
  #
54
72
  def each_char(&block)
55
73
  each { |b| block.call(b.chr) } if block
56
74
  end
57
75
 
58
76
  #
59
- # Selects an Array of characters from the character set that match
60
- # the given _block_.
77
+ # Selects characters from the character set.
78
+ #
79
+ # @yield [char]
80
+ # If a block is given, it will be used to select the characters
81
+ # from the character set.
82
+ #
83
+ # @yieldparam [String] char
84
+ # The character to select or reject.
85
+ #
86
+ # @return [Array<String>]
87
+ # The selected characters from the character set.
61
88
  #
62
89
  def select_chars(&block)
63
90
  chars.select(&block)
64
91
  end
65
92
 
66
93
  #
67
- # Maps the characters of the character set using the given _block_.
94
+ # Maps the characters of the character set.
95
+ #
96
+ # @yield [char]
97
+ # The given block will be used to transform the characters within
98
+ # the character set.
99
+ #
100
+ # @yieldparam [String] char
101
+ # Each character in the character set.
102
+ #
103
+ # @return [Array<String>]
104
+ # The mapped characters of the character set.
68
105
  #
69
106
  def map_chars(&block)
70
107
  chars.map(&block)
71
108
  end
72
109
 
73
110
  #
74
- # Returns a random byte from the character set.
111
+ # @return [Integer]
112
+ # A random byte from the character set.
75
113
  #
76
114
  def random_byte
77
115
  self.entries[rand(self.length)]
78
116
  end
79
117
 
80
118
  #
81
- # Returns a random char from the character set.
119
+ # @return [String]
120
+ # A random char from the character set.
82
121
  #
83
122
  def random_char
84
123
  random_byte.chr
85
124
  end
86
125
 
87
126
  #
88
- # Pass a random byte to the specified _block_, _n_ times.
127
+ # Pass random bytes to a given block.
128
+ #
129
+ # @param [Integer] n
130
+ # Specifies how many times to pass a random byte to the block.
131
+ #
132
+ # @yield [byte]
133
+ # The block will receive the random bytes.
134
+ #
135
+ # @yieldparam [Integer] byte
136
+ # The random byte from the character set.
137
+ #
138
+ # @return [Integer]
139
+ # The number of times the given block was passed random bytes.
89
140
  #
90
141
  def each_random_byte(n,&block)
91
142
  n.times { block.call(random_byte) }
92
143
  end
93
144
 
94
145
  #
95
- # Pass a random character to the specified _block_, _n_ times.
146
+ # Pass random characters to a given block.
147
+ #
148
+ # @param [Integer] n
149
+ # Specifies how many times to pass a random character to the block.
150
+ #
151
+ # @yield [char]
152
+ # The block will receive the random characters.
153
+ #
154
+ # @yieldparam [String] char
155
+ # The random character from the character set.
156
+ #
157
+ # @return [Integer]
158
+ # The number of times the given block was passed random characters.
96
159
  #
97
160
  def each_random_char(n,&block)
98
161
  each_random_byte(n) { |b| block.call(b.chr) }
99
162
  end
100
163
 
101
164
  #
102
- # Returns an Array of the specified _length_ containing
103
- # random bytes from the character set. The specified _length_ may
104
- # be an Integer, Array or a Range of lengths.
165
+ # Creates an Array of random bytes from the character set.
166
+ #
167
+ # @param [Integer, Array, Range] length
168
+ # The length of the Array of random bytes.
169
+ #
170
+ # @return [Array<Integer>]
171
+ # The randomly selected bytes.
105
172
  #
106
173
  def random_bytes(length)
107
174
  if (length.kind_of?(Array) || length.kind_of?(Range))
@@ -112,35 +179,99 @@ module Chars
112
179
  end
113
180
 
114
181
  #
115
- # Returns an Array of the specified _length_ containing
116
- # random characters from the character set. The specified _length_
117
- # may be an Integer, Array or a Range of lengths.
182
+ # Creates an Array of random non-repeating bytes from the character set.
183
+ #
184
+ # @param [Integer, Array, Range] length
185
+ # The length of the Array of random non-repeating bytes.
186
+ #
187
+ # @return [Array<Integer>]
188
+ # The randomly selected non-repeating bytes.
189
+ #
190
+ def random_distinct_bytes(length)
191
+ if (length.kind_of?(Array) || length.kind_of?(Range))
192
+ return self.entries.sort_by { rand }.slice(0...(length.sort_by { rand }.first))
193
+ else
194
+ return self.entries.sort_by { rand }.slice(0...length)
195
+ end
196
+ end
197
+
198
+ #
199
+ # Creates an Array of random characters from the character set.
200
+ #
201
+ # @param [Integer, Array, Range] length
202
+ # The length of the Array of random characters.
203
+ #
204
+ # @return [Array<String>]
205
+ # The randomly selected characters.
118
206
  #
119
207
  def random_chars(length)
120
208
  random_bytes(length).map { |b| b.chr }
121
209
  end
122
210
 
123
211
  #
124
- # Returns a String of the specified _length_ containing
125
- # random characters from the character set.
212
+ # Creates a String containing randomly selected characters from the
213
+ # character set.
214
+ #
215
+ # @param [Integer, Array, Range] length
216
+ # The length of the String of random characters.
217
+ #
218
+ # @return [String]
219
+ # The String of randomly selected characters.
220
+ #
221
+ # @see random_chars
126
222
  #
127
223
  def random_string(length)
128
224
  random_chars(length).join
129
225
  end
130
226
 
131
227
  #
132
- # Finds sub-strings within the specified _data_ that are part of the
133
- # character set, using the given _options_.
228
+ # Creates an Array of random non-repeating characters from the
229
+ # character set.
230
+ #
231
+ # @param [Integer, Array, Range] length
232
+ # The length of the Array of random non-repeating characters.
233
+ #
234
+ # @return [Array<Integer>]
235
+ # The randomly selected non-repeating characters.
236
+ #
237
+ def random_distinct_chars(length)
238
+ random_distinct_bytes(length).map { |b| b.chr }
239
+ end
240
+
241
+ #
242
+ # Creates a String containing randomly selected non-repeating
243
+ # characters from the character set.
244
+ #
245
+ # @param [Integer, Array, Range] length
246
+ # The length of the String of random non-repeating characters.
247
+ #
248
+ # @return [String]
249
+ # The String of randomly selected non-repeating characters.
134
250
  #
135
- # _options_ may contain the following keys:
136
- # <tt>:length</tt>:: The minimum length of matching sub-strings
137
- # within the _data_. Defaults to 4, if not
138
- # specified.
139
- # <tt>:offsets</tt>:: Specifies wether to return a Hash of the
140
- # offsets within the _data_ and the matched
141
- # sub-strings. If not specified a simple
142
- # Array will be returned of the matched
143
- # sub-strings.
251
+ # @see random_distinct_chars
252
+ #
253
+ def random_distinct_string(length)
254
+ random_distinct_chars(length).join
255
+ end
256
+
257
+
258
+ #
259
+ # Finds sub-strings within given data that are made of characters within
260
+ # the character set.
261
+ #
262
+ # @param [String] data
263
+ # The data to find sub-strings within.
264
+ #
265
+ # @param [Hash] options
266
+ # Additional options.
267
+ #
268
+ # @option options [Integer] :length (4)
269
+ # The minimum length of sub-strings found within the given data.
270
+ #
271
+ # @option options [Boolean] :offsets (false)
272
+ # Specifies whether to return a Hash of offsets and matched
273
+ # sub-strings within the data, or to just return the matched
274
+ # sub-strings themselves.
144
275
  #
145
276
  def strings_in(data,options={})
146
277
  min_length = (options[:length] || 4)
@@ -180,8 +311,14 @@ module Chars
180
311
  end
181
312
 
182
313
  #
183
- # Creates a new CharSet object containing the both the characters
184
- # of the character set and the specified _other_set_.
314
+ # Creates a new CharSet object by unioning the character set with
315
+ # another character set.
316
+ #
317
+ # @param [CharSet, Array, Range] other_set
318
+ # The other character set to union with.
319
+ #
320
+ # @return [CharSet]
321
+ # The unioned character sets.
185
322
  #
186
323
  def |(other_set)
187
324
  super(CharSet.new(other_set))
@@ -190,9 +327,17 @@ module Chars
190
327
  alias + |
191
328
 
192
329
  #
193
- # Returns +true+ if all of the bytes within the specified _string_
194
- # are included in the character set, returns +false+ otherwise.
330
+ # Compares the bytes within a given string with the bytes of the
331
+ # character set.
195
332
  #
333
+ # @param [String] string
334
+ # The string to compare with the character set.
335
+ #
336
+ # @return [Boolean]
337
+ # Specifies whether all of the bytes within the given string are
338
+ # included in the character set.
339
+ #
340
+ # @example
196
341
  # Chars.alpha === "hello"
197
342
  # # => true
198
343
  #
@@ -211,6 +356,9 @@ module Chars
211
356
  #
212
357
  # Inspects the character set.
213
358
  #
359
+ # @return [String]
360
+ # The inspected character set.
361
+ #
214
362
  def inspect
215
363
  "#<#{self.class.name}: {" + map { |b|
216
364
  case b
@@ -39,27 +39,38 @@ module Chars
39
39
  # The space character set
40
40
  SPACE = CharSet.new(' ', "\f", "\n", "\r", "\t", "\v")
41
41
 
42
+ # The set of printable characters (not including spaces)
43
+ VISIBLE = ALPHA_NUMERIC + ['\'', '"', '`', ',', ';', ':', '~', '-',
44
+ '(', ')', '[', ']', '{', '}', '.', '?', '!', '@', '#', '$',
45
+ '%', '^', '&', '*', '_', '+', '=', '|', '\\', '<', '>', '/']
46
+
42
47
  # The set of printable characters (including spaces)
43
48
  PRINTABLE = ALPHA_NUMERIC + PUNCTUATION + SYMBOLS + SPACE
44
49
 
45
50
  # The control-char character set
46
51
  CONTROL = CharSet.new(0..0x1f, 0x7f)
47
52
 
48
- # The ASCII character set
49
- ASCII = CharSet.new(0..0x7f)
53
+ # The signed ASCII character set
54
+ SIGNED_ASCII = CharSet.new(0..0x7f)
50
55
 
51
56
  # The full 8-bit character set
52
- ALL = CharSet.new(0..0xff)
57
+ ASCII = CharSet.new(0..0xff)
53
58
 
54
59
  #
55
- # The numeric decimal character set.
60
+ # The decimal-digit character set.
61
+ #
62
+ # @return [CharSet]
63
+ # The decimal-digit character set.
56
64
  #
57
65
  def Chars.numeric
58
66
  NUMERIC
59
67
  end
60
68
 
61
69
  #
62
- # The octal character set.
70
+ # The octal-digit character set.
71
+ #
72
+ # @return [CharSet]
73
+ # The octal-digit character set.
63
74
  #
64
75
  def Chars.octal
65
76
  OCTAL
@@ -68,6 +79,9 @@ module Chars
68
79
  #
69
80
  # The upper-case hexadecimal character set.
70
81
  #
82
+ # @return [CharSet]
83
+ # The upper-case hexadecimal character set.
84
+ #
71
85
  def Chars.uppercase_hexadecimal
72
86
  UPPERCASE_HEXADECIMAL
73
87
  end
@@ -75,6 +89,9 @@ module Chars
75
89
  #
76
90
  # The lower-case hexadecimal character set.
77
91
  #
92
+ # @return [CharSet]
93
+ # The lower-case hexadecimal character set.
94
+ #
78
95
  def Chars.lowercase_hexadecimal
79
96
  LOWERCASE_HEXADECIMAL
80
97
  end
@@ -82,26 +99,38 @@ module Chars
82
99
  #
83
100
  # The hexadecimal character set.
84
101
  #
102
+ # @return [CharSet]
103
+ # The hexadecimal character set.
104
+ #
85
105
  def Chars.hexadecimal
86
106
  HEXADECIMAL
87
107
  end
88
108
 
89
109
  #
90
- # The upper-case alpha character set.
110
+ # The upper-case alphabetic character set.
111
+ #
112
+ # @return [CharSet]
113
+ # The upper-case alphabetic character set.
91
114
  #
92
115
  def Chars.uppercase_alpha
93
116
  UPPERCASE_ALPHA
94
117
  end
95
118
 
96
119
  #
97
- # The lower-case alpha character set.
120
+ # The lower-case alphabetic character set.
121
+ #
122
+ # @return [CharSet]
123
+ # The lower-case alphabetic character set.
98
124
  #
99
125
  def Chars.lowercase_alpha
100
126
  LOWERCASE_ALPHA
101
127
  end
102
128
 
103
129
  #
104
- # The alpha character set.
130
+ # The alphabetic character set.
131
+ #
132
+ # @return [CharSet]
133
+ # The alphabetic character set.
105
134
  #
106
135
  def Chars.alpha
107
136
  ALPHA
@@ -110,6 +139,9 @@ module Chars
110
139
  #
111
140
  # The alpha-numeric character set.
112
141
  #
142
+ # @return [CharSet]
143
+ # The alpha-numeric character set.
144
+ #
113
145
  def Chars.alpha_numeric
114
146
  ALPHA_NUMERIC
115
147
  end
@@ -117,6 +149,9 @@ module Chars
117
149
  #
118
150
  # The punctuation character set.
119
151
  #
152
+ # @return [CharSet]
153
+ # The punctuation character set.
154
+ #
120
155
  def Chars.punctuation
121
156
  PUNCTUATION
122
157
  end
@@ -124,42 +159,70 @@ module Chars
124
159
  #
125
160
  # The symbolic character set.
126
161
  #
162
+ # @return [CharSet]
163
+ # The symbolic character set.
164
+ #
127
165
  def Chars.symbols
128
166
  SYMBOLS
129
167
  end
130
168
 
131
169
  #
132
- # The space character set.
170
+ # The white-space character set.
171
+ #
172
+ # @return [CharSet]
173
+ # The white-space character set.
133
174
  #
134
175
  def Chars.space
135
176
  SPACE
136
177
  end
137
178
 
179
+ #
180
+ # The set of printable characters, not including spaces.
181
+ #
182
+ # @return [CharSet]
183
+ # The visible character set.
184
+ #
185
+ def Chars.visible
186
+ VISIBLE
187
+ end
188
+
138
189
  #
139
190
  # The set of printable characters, including spaces.
140
191
  #
192
+ # @return [CharSet]
193
+ # The printable character set.
194
+ #
141
195
  def Chars.printable
142
196
  PRINTABLE
143
197
  end
144
198
 
145
199
  #
146
- # The control-char character set.
200
+ # The control-character character set.
201
+ #
202
+ # @return [CharSet]
203
+ # The control-character character set.
147
204
  #
148
205
  def Chars.control
149
206
  CONTROL
150
207
  end
151
208
 
152
209
  #
153
- # The ASCII character set.
210
+ # The signed ASCII character set.
154
211
  #
155
- def Chars.ascii
156
- ASCII
212
+ # @return [CharSet]
213
+ # The signed ASCII character set.
214
+ #
215
+ def Chars.signed_ascii
216
+ SIGNED_ASCII
157
217
  end
158
218
 
159
219
  #
160
- # The full 8-bit character set.
220
+ # The ASCII character set.
221
+ #
222
+ # @return [CharSet]
223
+ # The ASCII character set.
161
224
  #
162
- def Chars.all
163
- ALL
225
+ def Chars.ascii
226
+ ASCII
164
227
  end
165
228
  end
@@ -2,62 +2,215 @@ require 'chars/chars'
2
2
 
3
3
  class Integer
4
4
 
5
+ #
6
+ # Determines if the byte belongs to the decimal-digit character set.
7
+ #
8
+ # @return [Boolean]
9
+ # Specifies whether the byte belongs to the decimal-digit character set.
10
+ #
11
+ # @see Chars.numeric
12
+ #
5
13
  def numeric?
6
14
  Chars::NUMERIC.include?(self)
7
15
  end
8
16
 
17
+ #
18
+ # Determines if the byte belongs to the octal-digit character set.
19
+ #
20
+ # @return [Boolean]
21
+ # Specifies whether the byte belongs to the octal-digit character set.
22
+ #
23
+ # @see Chars.octal
24
+ #
9
25
  def octal?
10
26
  Chars::OCTAL.include?(self)
11
27
  end
12
28
 
29
+ #
30
+ # Determines if the byte belongs to the upper-case hexadecimal character
31
+ # set.
32
+ #
33
+ # @return [Boolean]
34
+ # Specifies whether the byte belongs to the upper-case hexadecimal
35
+ # character set.
36
+ #
37
+ # @see Chars.uppercase_hexadecimal
38
+ #
13
39
  def uppercase_hex?
14
40
  Chars::UPPERCASE_HEXADECIMAL.include?(self)
15
41
  end
16
42
 
43
+ #
44
+ # Determines if the byte belongs to the lower-case hexadecimal character
45
+ # set.
46
+ #
47
+ # @return [Boolean]
48
+ # Specifies whether the byte belongs to the lower-case hexadecimal
49
+ # character set.
50
+ #
51
+ # @see Chars.lowercase_hexadecimal
52
+ #
17
53
  def lowercase_hex?
18
54
  Chars::LOWERCASE_HEXADECIMAL.include?(self)
19
55
  end
20
56
 
57
+ #
58
+ # Determines if the byte belongs to the hexadecimal character set.
59
+ #
60
+ # @return [Boolean]
61
+ # Specifies whether the byte belongs to the hexadecimal character set.
62
+ #
63
+ # @see Chars.hexadecimal
64
+ #
21
65
  def hex?
22
66
  Chars::HEXADECIMAL.include?(self)
23
67
  end
24
68
 
69
+ #
70
+ # Determines if the byte belongs to the upper-case alphabetic character
71
+ # set.
72
+ #
73
+ # @return [Boolean]
74
+ # Specifies whether the byte belongs to the upper-case alphabetic
75
+ # character set.
76
+ #
77
+ # @see Chars.uppercase_alpha
78
+ #
25
79
  def uppercase_alpha?
26
80
  Chars::UPPERCASE_ALPHA.include?(self)
27
81
  end
28
82
 
83
+ #
84
+ # Determines if the byte belongs to the lower-case alphabetic character
85
+ # set.
86
+ #
87
+ # @return [Boolean]
88
+ # Specifies whether the byte belongs to the lower-case alphabetic
89
+ # character set.
90
+ #
91
+ # @see Chars.lowercase_alpha
92
+ #
29
93
  def lowercase_alpha?
30
94
  Chars::LOWERCASE_ALPHA.include?(self)
31
95
  end
32
96
 
97
+ #
98
+ # Determines if the byte belongs to the alphabetic character set.
99
+ #
100
+ # @return [Boolean]
101
+ # Specifies whether the byte belongs to the alphabetic character set.
102
+ #
103
+ # @see Chars.alpha
104
+ #
33
105
  def alpha?
34
106
  Chars::ALPHA.include?(self)
35
107
  end
36
108
 
109
+ #
110
+ # Determines if the byte belongs to the alpha-numeric character set.
111
+ #
112
+ # @return [Boolean]
113
+ # Specifies whether the byte belongs to the alpha-numeric character set.
114
+ #
115
+ # @see Chars.alpha_numeric
116
+ #
37
117
  def alpha_numeric?
38
118
  Chars::ALPHA_NUMERIC.include?(self)
39
119
  end
40
120
 
121
+ #
122
+ # Determines if the byte belongs to the punctuation character set.
123
+ #
124
+ # @return [Boolean]
125
+ # Specifies whether the byte belongs to the punctuation character set.
126
+ #
127
+ # @see Chars.punctuation
128
+ #
41
129
  def punctuation?
42
130
  Chars::PUNCTUATION.include?(self)
43
131
  end
44
132
 
133
+ #
134
+ # Determines if the byte belongs to the symbolic character set.
135
+ #
136
+ # @return [Boolean]
137
+ # Specifies whether the byte belongs to the symbolic character set.
138
+ #
139
+ # @see Chars.symbols
140
+ #
45
141
  def symbolic?
46
142
  Chars::SYMBOLS.include?(self)
47
143
  end
48
144
 
145
+ #
146
+ # Determines if the byte belongs to the white-space character set.
147
+ #
148
+ # @return [Boolean]
149
+ # Specifies whether the byte belongs to the white-space character set.
150
+ #
151
+ # @see Chars.space
152
+ #
49
153
  def space?
50
154
  Chars::SPACE.include?(self)
51
155
  end
52
156
 
157
+ #
158
+ # Determines if the byte belongs to the visible character set.
159
+ #
160
+ # @return [Boolean]
161
+ # Specifies whether the byte belongs to the visible character set.
162
+ #
163
+ # @see Chars.visible
164
+ #
165
+ def visible?
166
+ Chars::VISIBLE.include?(self)
167
+ end
168
+
169
+ #
170
+ # Determines if the byte belongs to the printable character set.
171
+ #
172
+ # @return [Boolean]
173
+ # Specifies whether the byte belongs to the printable character set.
174
+ #
175
+ # @see Chars.printable
176
+ #
53
177
  def printable?
54
178
  Chars::PRINTABLE.include?(self)
55
179
  end
56
180
 
181
+ #
182
+ # Determines if the byte belongs to the control-character character set.
183
+ #
184
+ # @return [Boolean]
185
+ # Specifies whether the byte belongs to the control-character character
186
+ # set.
187
+ #
188
+ # @see Chars.control
189
+ #
57
190
  def control?
58
191
  Chars::CONTROL.include?(self)
59
192
  end
60
193
 
194
+ #
195
+ # Determines if the byte belongs to the signed-ASCII character set.
196
+ #
197
+ # @return [Boolean]
198
+ # Specifies whether the byte belongs to the signed-ASCII character set.
199
+ #
200
+ # @see Chars.signed_ascii
201
+ #
202
+ def signed_ascii?
203
+ Chars::SIGNED_ASCII.include?(self)
204
+ end
205
+
206
+ #
207
+ # Determines if the byte belongs to the ASCII character set.
208
+ #
209
+ # @return [Boolean]
210
+ # Specifies whether the byte belongs to the ASCII character set.
211
+ #
212
+ # @see Chars.ascii
213
+ #
61
214
  def ascii?
62
215
  Chars::ASCII.include?(self)
63
216
  end
@@ -2,62 +2,221 @@ require 'chars/chars'
2
2
 
3
3
  class String
4
4
 
5
+ #
6
+ # Determines whether the String belongs to the decimal-digit character set.
7
+ #
8
+ # @return [Boolean]
9
+ # Specifies whether the String belongs to the decimal-digit character
10
+ # set.
11
+ #
12
+ # @see Chars.numeric
13
+ #
5
14
  def numeric?
6
15
  Chars::NUMERIC === self
7
16
  end
8
17
 
18
+ #
19
+ # Determines whether the String belongs to the octal-digit character set.
20
+ #
21
+ # @return [Boolean]
22
+ # Specifies whether the String belongs to the octal-digit character
23
+ # set.
24
+ #
25
+ # @see Chars.octal
26
+ #
9
27
  def octal?
10
28
  Chars::OCTAL === self
11
29
  end
12
30
 
31
+ #
32
+ # Determines whether the String belongs to the upper-case hexadecimal
33
+ # character set.
34
+ #
35
+ # @return [Boolean]
36
+ # Specifies whether the String belongs to the upper-case hexadecimal
37
+ # character set.
38
+ #
39
+ # @see Chars.uppercase_hexadecimal
40
+ #
13
41
  def uppercase_hex?
14
42
  Chars::UPPERCASE_HEXADECIMAL === self
15
43
  end
16
44
 
45
+ #
46
+ # Determines whether the String belongs to the lower-case hexadecimal
47
+ # character set.
48
+ #
49
+ # @return [Boolean]
50
+ # Specifies whether the String belongs to the lower-case hexadecimal
51
+ # character set.
52
+ #
53
+ # @see Chars.lowercase_hexadecimal
54
+ #
17
55
  def lowercase_hex?
18
56
  Chars::LOWERCASE_HEXADECIMAL === self
19
57
  end
20
58
 
59
+ #
60
+ # Determines whether the String belongs to the hexadecimal character set.
61
+ #
62
+ # @return [Boolean]
63
+ # Specifies whether the String belongs to the hexadecimal character set.
64
+ #
65
+ # @see Chars.hexadecimal
66
+ #
21
67
  def hex?
22
68
  Chars::HEXADECIMAL === self
23
69
  end
24
70
 
71
+ #
72
+ # Determines whether the String belongs to the upper-case alphabetic
73
+ # character set.
74
+ #
75
+ # @return [Boolean]
76
+ # Specifies whether the String belongs to the upper-case alphabetic
77
+ # character set.
78
+ #
79
+ # @see Chars.uppercase_alpha
80
+ #
25
81
  def uppercase_alpha?
26
82
  Chars::UPPERCASE_ALPHA === self
27
83
  end
28
84
 
85
+ #
86
+ # Determines whether the String belongs to the lower-case alphabetic
87
+ # character set.
88
+ #
89
+ # @return [Boolean]
90
+ # Specifies whether the String belongs to the lower-case alphabetic
91
+ # character set.
92
+ #
93
+ # @see Chars.lowercase_alpha
94
+ #
29
95
  def lowercase_alpha?
30
96
  Chars::LOWERCASE_ALPHA === self
31
97
  end
32
98
 
99
+ #
100
+ # Determines whether the String belongs to the alphabetic character set.
101
+ #
102
+ # @return [Boolean]
103
+ # Specifies whether the String belongs to the alphabetic character set.
104
+ #
105
+ # @see Chars.alpha
106
+ #
33
107
  def alpha?
34
108
  Chars::ALPHA === self
35
109
  end
36
110
 
111
+ #
112
+ # Determines whether the String belongs to the alpha-numeric character
113
+ # set.
114
+ #
115
+ # @return [Boolean]
116
+ # Specifies whether the String belongs to the alpha-numeric character
117
+ # set.
118
+ #
119
+ # @see Chars.alpha_numeric
120
+ #
37
121
  def alpha_numeric?
38
122
  Chars::ALPHA_NUMERIC === self
39
123
  end
40
124
 
125
+ #
126
+ # Determines whether the String belongs to the punctuation character set.
127
+ #
128
+ # @return [Boolean]
129
+ # Specifies whether the String belongs to the punctuation character set.
130
+ #
131
+ # @see Chars.punctuation
132
+ #
41
133
  def punctuation?
42
134
  Chars::PUNCTUATION === self
43
135
  end
44
136
 
137
+ #
138
+ # Determines whether the String belongs to the symbolic character set.
139
+ #
140
+ # @return [Boolean]
141
+ # Specifies whether the String belongs to the symbolic character set.
142
+ #
143
+ # @see Chars.symbols
144
+ #
45
145
  def symbolic?
46
146
  Chars::SYMBOLS === self
47
147
  end
48
148
 
149
+ #
150
+ # Determines whether the String belongs to the white-space character set.
151
+ #
152
+ # @return [Boolean]
153
+ # Specifies whether the String belongs to the white-space character set.
154
+ #
155
+ # @see Chars.space
156
+ #
49
157
  def space?
50
158
  Chars::SPACE === self
51
159
  end
52
160
 
161
+ #
162
+ # Determines whether the String belongs to the visible character set.
163
+ #
164
+ # @return [Boolean]
165
+ # Specifies whether the String belongs to the visible character set.
166
+ #
167
+ # @see Chars.visible
168
+ #
169
+ def visible?
170
+ Chars::VISIBLE === self
171
+ end
172
+
173
+ #
174
+ # Determines whether the String belongs to the printable character set.
175
+ #
176
+ # @return [Boolean]
177
+ # Specifies whether the String belongs to the printable character set.
178
+ #
179
+ # @see Chars.printable
180
+ #
53
181
  def printable?
54
182
  Chars::PRINTABLE === self
55
183
  end
56
184
 
185
+ #
186
+ # Determines whether the String belongs to the control-character
187
+ # character set.
188
+ #
189
+ # @return [Boolean]
190
+ # Specifies whether the String belongs to the control-character
191
+ # character set.
192
+ #
193
+ # @see Chars.control
194
+ #
57
195
  def control?
58
196
  Chars::CONTROL === self
59
197
  end
60
198
 
199
+ #
200
+ # Determines whether the String belongs to the signed-ASCII character set.
201
+ #
202
+ # @return [Boolean]
203
+ # Specifies whether the String belongs to the signed-ASCII character
204
+ # set.
205
+ #
206
+ # @see Chars.signed_ascii
207
+ #
208
+ def signed_ascii?
209
+ Chars::SIGNED_ASCII === self
210
+ end
211
+
212
+ #
213
+ # Determines whether the String belongs to the ASCII character set.
214
+ #
215
+ # @return [Boolean]
216
+ # Specifies whether the String belongs to the ASCII character set.
217
+ #
218
+ # @see Chars.ascii
219
+ #
61
220
  def ascii?
62
221
  Chars::ASCII === self
63
222
  end
@@ -1,4 +1,4 @@
1
1
  module Chars
2
2
  # Chars version
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe Chars::CharSet do
6
6
  before(:all) do
7
7
  @integer_range = (0x41..0x43)
8
- @string_range = ('A'..'C')
8
+ @string_range = ('A'..'Z')
9
9
  @integers = @integer_range.to_a
10
10
  @strings = @string_range.to_a
11
11
 
@@ -148,17 +148,51 @@ describe Chars::CharSet do
148
148
  @char_set.include?(b).should == true
149
149
  end
150
150
  end
151
+
152
+ it "should return a random Array of unique bytes" do
153
+ bytes = @char_set.random_distinct_bytes(10)
154
+ bytes.uniq.length.should == bytes.length
155
+ bytes.each do |b|
156
+ @char_set.include?(b).should == true
157
+ end
158
+ end
159
+
160
+ it "should return a random Array of unique chars" do
161
+ chars = @char_set.random_distinct_chars(10)
162
+ chars.uniq.length.should == chars.length
163
+ chars.each do |c|
164
+ @char_set.include_char?(c).should == true
165
+ end
166
+ end
167
+
168
+ it "should return a random Array of unique bytes with a varying length" do
169
+ bytes = @char_set.random_distinct_bytes(5..10)
170
+ bytes.uniq.length.should == bytes.length
171
+ bytes.length.between?(5, 10).should == true
172
+ bytes.each do |b|
173
+ @char_set.include?(b).should == true
174
+ end
175
+ end
176
+
177
+ it "should return a random Array of unique chars with a varying length" do
178
+ chars = @char_set.random_distinct_chars(5..10)
179
+ chars.uniq.length.should == chars.length
180
+ chars.length.between?(5, 10).should == true
181
+ chars.each do |c|
182
+ @char_set.include_char?(c).should == true
183
+ end
184
+ end
185
+
151
186
 
152
187
  it "should be able to be compared with another set of chars" do
153
- (@char_set == Chars::CharSet['A', 'B', 'C']).should == true
154
- (@char_set == Chars::CharSet['A', 'C', 'B']).should == true
188
+ (@char_set == Chars::CharSet[('A'..'Z')]).should == true
155
189
  end
156
190
 
157
191
  it "should be able to be unioned with another set of chars" do
158
192
  super_set = (@char_set | Chars::CharSet['D'])
159
193
 
160
194
  super_set.class.should == Chars::CharSet
161
- super_set.should == Chars::CharSet['A', 'B', 'C', 'D']
195
+ super_set.should == Chars::CharSet[('A'..'Z'), 'D']
162
196
  end
163
197
 
164
198
  it "should be able to be removed from another set of chars" do
@@ -173,7 +207,7 @@ describe Chars::CharSet do
173
207
  end
174
208
 
175
209
  it "should find sub-strings from a String belonging to the char set" do
176
- @char_set.strings_in("AAAAXBXCCCCCC").should == [
210
+ @char_set.strings_in("AAAA!B!CCCCCC").should == [
177
211
  "AAAA",
178
212
  "CCCCCC"
179
213
  ]
@@ -181,6 +215,6 @@ describe Chars::CharSet do
181
215
 
182
216
  it "should determine if a String is made up of the characters from the char set" do
183
217
  (@char_set === "AABCBAA").should == true
184
- (@char_set === "AADDEE").should_not == true
218
+ (@char_set === "AA!!EE").should_not == true
185
219
  end
186
220
  end
@@ -17,8 +17,9 @@ describe Chars do
17
17
  @punctuation_string = Chars.punctuation.random_string(10)
18
18
  @symbols_string = Chars.symbols.random_string(10)
19
19
  @control_string = Chars.control.random_string(10)
20
+ @signed_ascii_string = Chars.signed_ascii.random_string(10)
20
21
  @ascii_string = Chars.ascii.random_string(10)
21
- @all_string = Chars.all.random_string(10)
22
+ @visible_string = Chars.visible.random_string(10)
22
23
  end
23
24
 
24
25
  it "should provide a numeric CharSet" do
@@ -83,6 +84,13 @@ describe Chars do
83
84
  Chars::ALPHA_NUMERIC.include?(b).should == true
84
85
  end
85
86
  end
87
+
88
+ it "should provide a visible CharSet" do
89
+ @visible_string.length.should == 10
90
+ @visible_string.each_byte do |b|
91
+ Chars::VISIBLE.include?(b).should == true
92
+ end
93
+ end
86
94
 
87
95
  it "should provide a space CharSet" do
88
96
  @space_string.length.should == 10
@@ -51,6 +51,11 @@ describe Integer do
51
51
  0x20.should be_space
52
52
  end
53
53
 
54
+ it "should recognize visible bytes" do
55
+ 0x41.should be_visible
56
+ 0x20.should_not be_visible
57
+ end
58
+
54
59
  it "should recognize printable bytes" do
55
60
  0x3f.should be_printable
56
61
  end
@@ -59,7 +64,11 @@ describe Integer do
59
64
  0x1b.should be_control
60
65
  end
61
66
 
67
+ it "should recognize signed ASCII bytes" do
68
+ 0x00.should be_signed_ascii
69
+ end
70
+
62
71
  it "should recognize ASCII bytes" do
63
- 0x00.should be_ascii
72
+ 0x80.should be_ascii
64
73
  end
65
74
  end
@@ -51,6 +51,11 @@ describe String do
51
51
  " \t".should be_space
52
52
  end
53
53
 
54
+ it "should recognize visible strings" do
55
+ "abc".should be_visible
56
+ "ab c".should_not be_visible
57
+ end
58
+
54
59
  it "should recognize printable strings" do
55
60
  "abc, [123]\nDEF".should be_printable
56
61
  end
@@ -59,7 +64,11 @@ describe String do
59
64
  "\b\b\a".should be_control
60
65
  end
61
66
 
67
+ it "should recognize signed ASCII strings" do
68
+ "lol\0".should be_signed_ascii
69
+ end
70
+
62
71
  it "should recognize ASCII strings" do
63
- "lol\0".should be_ascii
72
+ "\xff\xfe".should be_ascii
64
73
  end
65
74
  end
@@ -6,4 +6,5 @@ Spec::Rake::SpecTask.new(:spec) do |t|
6
6
  t.spec_opts = ['--colour', '--format', 'specdoc']
7
7
  end
8
8
 
9
+ task :test => :spec
9
10
  task :default => :spec
metadata CHANGED
@@ -1,17 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chars
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
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
14
+ bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
+ ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
16
+ BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
+ 1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
19
+ mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
20
+ W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
21
+ 7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
22
+ +Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
23
+ T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
25
+ ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
26
+ xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
27
+ cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
28
+ GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
29
+ /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
30
+ pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
+ -----END CERTIFICATE-----
11
32
 
12
- date: 2009-04-12 00:00:00 -07:00
33
+ date: 2009-09-25 00:00:00 -07:00
13
34
  default_executable:
14
35
  dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.2.3.5
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.8
55
+ version:
15
56
  - !ruby/object:Gem::Dependency
16
57
  name: hoe
17
58
  type: :development
@@ -20,9 +61,11 @@ dependencies:
20
61
  requirements:
21
62
  - - ">="
22
63
  - !ruby/object:Gem::Version
23
- version: 1.12.1
64
+ version: 2.3.3
24
65
  version:
25
- description: Chars is a Ruby library for working with various character sets, recognizing text and generating random text from specific character sets.
66
+ description: |-
67
+ Chars is a Ruby library for working with various character sets,
68
+ recognizing text and generating random text from specific character sets.
26
69
  email:
27
70
  - postmodern.mod3@gmail.com
28
71
  executables: []
@@ -53,8 +96,10 @@ files:
53
96
  - spec/chars_spec.rb
54
97
  - spec/integer_spec.rb
55
98
  - spec/string_spec.rb
56
- has_rdoc: true
99
+ has_rdoc: yard
57
100
  homepage: http://chars.rubyforge.org/
101
+ licenses: []
102
+
58
103
  post_install_message:
59
104
  rdoc_options:
60
105
  - --main
@@ -76,9 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
121
  requirements: []
77
122
 
78
123
  rubyforge_project: chars
79
- rubygems_version: 1.3.1
124
+ rubygems_version: 1.3.5
80
125
  signing_key:
81
- specification_version: 2
126
+ specification_version: 3
82
127
  summary: Chars is a Ruby library for working with various character sets, recognizing text and generating random text from specific character sets.
83
128
  test_files: []
84
129
 
@@ -0,0 +1,4 @@
1
+ m� �8��‰�؈� ��&���I�Ҏܸ�g�I �i�:��w�ٓ�FJTn��:��gY��e���9������t��G�vhF(I�(���q���P�I�2�.ʶ(���M
2
+
3
+ ��
4
+ ;��`��!�2��g6k�d=t���z���W���?�]�XԀ��$�{X&��_� "}��$:֭����$��$�w�V��&��yqc{�,j�Ӝ���C�w����