brightbox-rujitsu 0.1.9 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +4 -1
- data/lib/rujitsu/fixnum.rb +22 -10
- data/rujitsu.gemspec +2 -2
- data/spec/fixnum_spec.rb +79 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('rujitsu', '0.
|
5
|
+
Echoe.new('rujitsu', '0.2') do | config |
|
6
6
|
config.description = 'Various helper methods to smooth over Ruby development'
|
7
7
|
config.url = 'http://github.com/rahoub/rujitsu'
|
8
8
|
config.author = 'Brightbox Systems Ltd'
|
@@ -11,6 +11,9 @@ Echoe.new('rujitsu', '0.1.9') do | config |
|
|
11
11
|
config.development_dependencies = []
|
12
12
|
end
|
13
13
|
|
14
|
+
desc "Generates manifest & gemspec in one go"
|
15
|
+
task :build => [:manifest, :build_gemspec]
|
16
|
+
|
14
17
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each do | rake_file |
|
15
18
|
load rake_file
|
16
19
|
end
|
data/lib/rujitsu/fixnum.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
class Fixnum
|
2
2
|
# produce a string of N random vowels
|
3
|
-
def random_vowels
|
4
|
-
generate_random_string_using VOWELS
|
3
|
+
def random_vowels opts={}
|
4
|
+
generate_random_string_using VOWELS, opts
|
5
5
|
end
|
6
6
|
# produce a string of N random consonants
|
7
|
-
def random_consonants
|
8
|
-
generate_random_string_using CONSONANTS
|
7
|
+
def random_consonants opts={}
|
8
|
+
generate_random_string_using CONSONANTS, opts
|
9
9
|
end
|
10
10
|
# produce a string of N random letters
|
11
11
|
# 5.random_letters
|
12
|
-
def random_letters
|
13
|
-
generate_random_string_using LETTERS
|
12
|
+
def random_letters opts={}
|
13
|
+
generate_random_string_using LETTERS, opts
|
14
14
|
end
|
15
15
|
# produce a string of N random numbers
|
16
16
|
# 5.random_numbers
|
@@ -34,13 +34,13 @@ class Fixnum
|
|
34
34
|
end
|
35
35
|
# produce a string of N random characters
|
36
36
|
# 5.random_characters
|
37
|
-
def random_characters
|
38
|
-
generate_random_string_using CHARACTERS
|
37
|
+
def random_characters opts={}
|
38
|
+
generate_random_string_using CHARACTERS, opts
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
VOWELS =
|
43
|
+
VOWELS = %w(a e i o u)
|
44
44
|
LETTERS = ('a'..'z').to_a
|
45
45
|
CONSONANTS = LETTERS - VOWELS
|
46
46
|
NUMBERS = ('0'..'9').to_a
|
@@ -48,8 +48,20 @@ class Fixnum
|
|
48
48
|
EVENS = %w(0 2 4 6 8).map {|x| x.to_i }
|
49
49
|
ODDS = %w(1 3 5 7 9).map {|x| x.to_i }
|
50
50
|
|
51
|
-
def generate_random_string_using(legal_characters)
|
51
|
+
def generate_random_string_using(legal_characters, opts={})
|
52
|
+
# Check if we have anything to exclude from the legal_characters
|
53
|
+
if (chars = opts[:except])
|
54
|
+
# Make sure we can iterate over it
|
55
|
+
chars = [chars] unless chars.respond_to?(:each)
|
56
|
+
# Run through them all and remove them
|
57
|
+
chars.each do | char |
|
58
|
+
legal_characters.delete(char)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
52
62
|
upper_limit = legal_characters.size - 1
|
63
|
+
|
64
|
+
srand # seed rand
|
53
65
|
(1..self).collect do |num|
|
54
66
|
legal_characters[rand(upper_limit)]
|
55
67
|
end.join
|
data/rujitsu.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rujitsu}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brightbox Systems Ltd"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-04-06}
|
10
10
|
s.description = %q{Various helper methods to smooth over Ruby development}
|
11
11
|
s.email = %q{hello@brightbox.co.uk}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/rujitsu/fixnum.rb", "lib/rujitsu/grammar.rb", "lib/rujitsu/numeric.rb", "lib/rujitsu/range.rb", "lib/rujitsu/string.rb", "lib/rujitsu.rb", "README.rdoc", "tasks/rspec.rake"]
|
data/spec/fixnum_spec.rb
CHANGED
@@ -16,6 +16,22 @@ describe Fixnum do
|
|
16
16
|
str.should match( /^[aeiou]+$/ )
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
it "should exclude a character" do
|
21
|
+
# Given there are 5 vowels, 5^3 should
|
22
|
+
# contain at least one instance of every vowel
|
23
|
+
str = (5**3).random_vowels(:except => "a")
|
24
|
+
str.should be_a_kind_of( String )
|
25
|
+
str.length.should == 5**3
|
26
|
+
str.should_not match(/a/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should exclude characters" do
|
30
|
+
str = (5**3).random_vowels(:except => %w(i o u))
|
31
|
+
str.should be_a_kind_of( String )
|
32
|
+
str.length.should == 5**3
|
33
|
+
str.should_not match(/iou/)
|
34
|
+
end
|
19
35
|
end
|
20
36
|
|
21
37
|
describe "random_consonants" do
|
@@ -27,11 +43,32 @@ describe Fixnum do
|
|
27
43
|
it "should produce a string of random consonants" do
|
28
44
|
[ 5, 10, 15, 25, 29 ].each do |i|
|
29
45
|
str = i.random_consonants
|
46
|
+
|
30
47
|
str.should be_a_kind_of( String )
|
31
48
|
str.length.should == i
|
32
49
|
str.should match( /^[bcdfghjklmnpqrstvwxyz]+$/ )
|
33
50
|
end
|
34
51
|
end
|
52
|
+
|
53
|
+
it "should exclude a character" do
|
54
|
+
# 26^5 should be large enough to get at least one
|
55
|
+
# instance of every character.
|
56
|
+
str = (26**2).random_consonants(:except => "c")
|
57
|
+
|
58
|
+
str.should be_a_kind_of( String )
|
59
|
+
str.length.should == (26**2)
|
60
|
+
str.should_not match(/c/)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should exclude characters" do
|
64
|
+
# 26^5 should be large enough to get at least one
|
65
|
+
# instance of every character.
|
66
|
+
str = (26**2).random_consonants(:except => %w(c d f))
|
67
|
+
|
68
|
+
str.should be_a_kind_of( String )
|
69
|
+
str.length.should == (26**2)
|
70
|
+
str.should_not match(/cdf/)
|
71
|
+
end
|
35
72
|
end
|
36
73
|
|
37
74
|
describe "random_letters" do
|
@@ -48,6 +85,26 @@ describe Fixnum do
|
|
48
85
|
str.should match( /^[a-z]+$/ )
|
49
86
|
end
|
50
87
|
end
|
88
|
+
|
89
|
+
it "should exclude a character" do
|
90
|
+
# 26^5 should be large enough to get at least one
|
91
|
+
# instance of every character.
|
92
|
+
str = (26**2).random_letters(:except => "d")
|
93
|
+
|
94
|
+
str.should be_a_kind_of( String )
|
95
|
+
str.length.should == (26**2)
|
96
|
+
str.should_not match(/d/)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should exclude characters" do
|
100
|
+
# 26^5 should be large enough to get at least one
|
101
|
+
# instance of every character.
|
102
|
+
str = (26**2).random_letters(:except => %w(c d f))
|
103
|
+
|
104
|
+
str.should be_a_kind_of( String )
|
105
|
+
str.length.should == (26**2)
|
106
|
+
str.should_not match(/cdf/)
|
107
|
+
end
|
51
108
|
end
|
52
109
|
|
53
110
|
describe "random_numbers" do
|
@@ -138,6 +195,28 @@ describe Fixnum do
|
|
138
195
|
str.should match( /^[a-z0-9]+$/ )
|
139
196
|
end
|
140
197
|
end
|
198
|
+
|
199
|
+
|
200
|
+
it "should exclude a character" do
|
201
|
+
# 26^5 should be large enough to get at least one
|
202
|
+
# instance of every character.
|
203
|
+
str = (26**2).random_characters(:except => "c")
|
204
|
+
|
205
|
+
str.should be_a_kind_of( String )
|
206
|
+
str.length.should == (26**2)
|
207
|
+
str.should_not match(/c/)
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
it "should exclude characters" do
|
212
|
+
# 26^5 should be large enough to get at least one
|
213
|
+
# instance of every character.
|
214
|
+
str = (26**2).random_characters(:except => %w(c d f))
|
215
|
+
|
216
|
+
str.should be_a_kind_of( String )
|
217
|
+
str.length.should == (26**2)
|
218
|
+
str.should_not match(/cdf/)
|
219
|
+
end
|
141
220
|
end
|
142
221
|
|
143
222
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brightbox-rujitsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brightbox Systems Ltd
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|