rujitsu 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,5 +1,4 @@
1
1
  CHANGELOG
2
- Manifest
3
2
  README.rdoc
4
3
  Rakefile
5
4
  lib/rujitsu.rb
@@ -11,6 +10,7 @@ lib/rujitsu/numeric.rb
11
10
  lib/rujitsu/object.rb
12
11
  lib/rujitsu/range.rb
13
12
  lib/rujitsu/string.rb
13
+ lib/ujitsu.rb
14
14
  rujitsu.gemspec
15
15
  spec/fixnum_spec.rb
16
16
  spec/numeric_spec.rb
@@ -20,3 +20,4 @@ spec/spec.opts
20
20
  spec/spec_helper.rb
21
21
  spec/string_spec.rb
22
22
  tasks/rspec.rake
23
+ Manifest
data/README.rdoc CHANGED
@@ -11,12 +11,21 @@ A ruby gem with various helper methods to smooth out your Ruby development.
11
11
  require "rujitsu"
12
12
  require "rujitsu/grammar"
13
13
 
14
+ For using in irb, there's a nice shortcut for you to use:
15
+
16
+ $ irb -rubygems -rujitsu
17
+
18
+ (This works because <tt>-r</tt> is the argument to require a file, and both 'ubygems.rb' and 'ujitsu.rb' exist.)
19
+
14
20
  === Rails
15
21
 
16
22
  To require in rails 2.2, add the following to your <tt>environment.rb</tt> file.
17
23
 
18
- config.gem "brightbox-rujitsu", :lib => "rujitsu", :source => "http://gems.github.com"
19
- config.gem "brightbox-rujitsu", :lib => "rujitsu/grammar", :source => "http://gems.github.com"
24
+ config.gem "rujitsu"
25
+
26
+ If you use RSpec you might want to add the following to your <tt>environments/test.rb</tt>:
27
+
28
+ config.gem "rujitsu", :lib => "rujitsu/grammar"
20
29
 
21
30
  == Documentation
22
31
 
@@ -37,7 +46,9 @@ You can also generate a variable length string.
37
46
  (3..5).random_letters
38
47
 
39
48
  This generates a string of random letters whose length is 3, 4 or 5 characters.
40
-
49
+
50
+ <em>(All the above methods exist in the singular too. eg, <tt>1.random_letter</tt>)</em>
51
+
41
52
  === URL-friendly strings
42
53
 
43
54
  The String class has an extension that strips out URL-unfriendly characters.
data/Rakefile CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rujitsu', '0.3.1') do | config |
5
+ Echoe.new('rujitsu', '0.3.3') do | config |
6
6
  config.description = 'Various helper methods to smooth over Ruby development'
7
- config.url = 'http://github.com/rahoub/rujitsu'
7
+ config.url = 'http://github.com/brightbox/rujitsu'
8
8
  config.author = 'Brightbox Systems Ltd'
9
9
  config.email = 'hello@brightbox.co.uk'
10
10
  config.ignore_pattern = ['tmp/*', 'script/*']
@@ -1,17 +1,23 @@
1
- class Fixnum
1
+ module RujitsuFixnum
2
2
  # produce a string of N random vowels
3
3
  def random_vowels opts={}
4
4
  generate_random_string_using VOWELS, opts
5
5
  end
6
+ alias_method :random_vowel, :random_vowels
7
+
6
8
  # produce a string of N random consonants
7
9
  def random_consonants opts={}
8
10
  generate_random_string_using CONSONANTS, opts
9
11
  end
12
+ alias_method :random_consonant, :random_consonants
13
+
10
14
  # produce a string of N random letters
11
15
  # 5.random_letters
12
16
  def random_letters opts={}
13
17
  generate_random_string_using LETTERS, opts
14
18
  end
19
+ alias_method :random_letter, :random_letters
20
+
15
21
  # produce a string of N random numbers
16
22
  # 5.random_numbers
17
23
  # optionally specific limits on the numbers
@@ -32,12 +38,20 @@ class Fixnum
32
38
  n << end_number_choices(only).select {|x| (lower <= x) && (x <= upper) }.sort_by { rand }.first.to_s
33
39
  n.join("")
34
40
  end
41
+ alias_method :random_number, :random_numbers
42
+
35
43
  # produce a string of N random characters
36
44
  # 5.random_characters
37
45
  def random_characters opts={}
38
46
  generate_random_string_using CHARACTERS, opts
39
47
  end
40
-
48
+ alias_method :random_character, :random_characters
49
+
50
+ def random_hex_characters opts={}
51
+ generate_random_string_using HEX_CHARACTERS, opts
52
+ end
53
+ alias_method :random_hex_character, :random_hex_characters
54
+
41
55
  private
42
56
 
43
57
  VOWELS = %w(a e i o u)
@@ -47,6 +61,7 @@ class Fixnum
47
61
  CHARACTERS = LETTERS + NUMBERS
48
62
  EVENS = %w(0 2 4 6 8).map {|x| x.to_i }
49
63
  ODDS = %w(1 3 5 7 9).map {|x| x.to_i }
64
+ HEX_CHARACTERS = NUMBERS | ('a'..'f').to_a
50
65
 
51
66
  def generate_random_string_using(legal_characters, opts={})
52
67
  # Check if we have anything to exclude from the legal_characters
@@ -78,3 +93,5 @@ class Fixnum
78
93
  end
79
94
  end
80
95
  end
96
+
97
+ Fixnum.send(:include, RujitsuFixnum)
@@ -1,4 +1,4 @@
1
- class Numeric
1
+ module RujitsuNumeric
2
2
  # convert float values to "cents"
3
3
  # my_value = 2.5
4
4
  # my_value.to_cents # => 250
@@ -6,3 +6,5 @@ class Numeric
6
6
  (self * 100.0).to_i
7
7
  end
8
8
  end
9
+
10
+ Numeric.send(:include, RujitsuNumeric)
@@ -1,7 +1,9 @@
1
- class Object
1
+ module RujitsuObject
2
2
  # return true if this object is within the given container
3
3
  # if the supplied container does not respond to include? then an equality test is used instead
4
4
  def in? container
5
5
  container.respond_to?(:include?) ? container.include?(self) : container == self
6
6
  end
7
- end
7
+ end
8
+
9
+ Object.send(:include, RujitsuObject)
data/lib/rujitsu/range.rb CHANGED
@@ -1,26 +1,33 @@
1
- class Range
1
+ module RujitsuRange
2
2
  # pull a random element out of this range
3
3
  def to_random_i
4
4
  self.to_a.sort_by { rand }.first
5
5
  end
6
-
6
+
7
7
  # create a string of random letters whose length is one of the values in your range
8
8
  # (3..4).random_letters # => returns a string or 3 or 4 random letters
9
9
  def random_letters
10
10
  self.to_random_i.random_letters
11
11
  end
12
-
12
+
13
13
  # create a string of random numbers whose length is one of the values in your range
14
14
  # (3..4).random_numbers # => returns a string or 3 or 4 random numbers
15
15
  def random_numbers opts = {}
16
16
  self.to_random_i.random_numbers opts
17
17
  end
18
-
18
+
19
19
  # create a string of random characters whose length is one of the values in your range
20
20
  # (3..4).random_characters # => returns a string or 3 or 4 random characters
21
21
  def random_characters
22
22
  self.to_random_i.random_characters
23
23
  end
24
-
24
+
25
+ # create a string of random hex characters whose length is one of the values in your range
26
+ # (3..4).random_hex_characters # => returns a string of 3 or 4 random hex characters
27
+ def random_hex_characters
28
+ self.to_random_i.random_hex_characters
29
+ end
30
+
25
31
  end
26
32
 
33
+ Range.send(:include, RujitsuRange)
@@ -1,4 +1,4 @@
1
- class String
1
+ module RujitsuString
2
2
  # Return a string that can be used as part of a url
3
3
  # replaces basic "bad" characters with "-"
4
4
  def to_url
@@ -24,3 +24,5 @@ class String
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ String.send(:include, RujitsuString)
data/lib/ujitsu.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rujitsu.rb"
data/rujitsu.gemspec CHANGED
@@ -2,27 +2,27 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rujitsu}
5
- s.version = "0.3.1"
5
+ s.version = "0.3.3"
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-12-04}
9
+ s.date = %q{2010-06-03}
10
10
  s.description = %q{Various helper methods to smooth over Ruby development}
11
11
  s.email = %q{hello@brightbox.co.uk}
12
- s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/rujitsu.rb", "lib/rujitsu/all.rb", "lib/rujitsu/fixnum.rb", "lib/rujitsu/grammar.rb", "lib/rujitsu/inspect.rb", "lib/rujitsu/numeric.rb", "lib/rujitsu/object.rb", "lib/rujitsu/range.rb", "lib/rujitsu/string.rb", "tasks/rspec.rake"]
13
- s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "lib/rujitsu.rb", "lib/rujitsu/all.rb", "lib/rujitsu/fixnum.rb", "lib/rujitsu/grammar.rb", "lib/rujitsu/inspect.rb", "lib/rujitsu/numeric.rb", "lib/rujitsu/object.rb", "lib/rujitsu/range.rb", "lib/rujitsu/string.rb", "rujitsu.gemspec", "spec/fixnum_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/range_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "tasks/rspec.rake"]
14
- s.homepage = %q{http://github.com/rahoub/rujitsu}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/rujitsu.rb", "lib/rujitsu/all.rb", "lib/rujitsu/fixnum.rb", "lib/rujitsu/grammar.rb", "lib/rujitsu/inspect.rb", "lib/rujitsu/numeric.rb", "lib/rujitsu/object.rb", "lib/rujitsu/range.rb", "lib/rujitsu/string.rb", "lib/ujitsu.rb", "tasks/rspec.rake"]
13
+ s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "lib/rujitsu.rb", "lib/rujitsu/all.rb", "lib/rujitsu/fixnum.rb", "lib/rujitsu/grammar.rb", "lib/rujitsu/inspect.rb", "lib/rujitsu/numeric.rb", "lib/rujitsu/object.rb", "lib/rujitsu/range.rb", "lib/rujitsu/string.rb", "lib/ujitsu.rb", "rujitsu.gemspec", "spec/fixnum_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/range_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "tasks/rspec.rake", "Manifest"]
14
+ s.homepage = %q{http://github.com/brightbox/rujitsu}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{rujitsu}
18
- s.rubygems_version = %q{1.3.5}
18
+ s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{Various helper methods to smooth over Ruby development}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
23
  s.specification_version = 3
24
24
 
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
26
  else
27
27
  end
28
28
  else
data/spec/fixnum_spec.rb CHANGED
@@ -7,7 +7,12 @@ describe Fixnum do
7
7
  Fixnum.instance_methods.should include("random_vowels")
8
8
  5.should respond_to(:random_vowels)
9
9
  end
10
-
10
+
11
+ it "should be alias'd as random_vowel" do
12
+ Fixnum.instance_methods.should include("random_vowel")
13
+ 5.should respond_to(:random_vowel)
14
+ end
15
+
11
16
  it "should produce a string of random vowels" do
12
17
  [ 5, 10, 15, 25, 29 ].each do |i|
13
18
  str = i.random_vowels
@@ -39,7 +44,12 @@ describe Fixnum do
39
44
  Fixnum.instance_methods.should include("random_consonants")
40
45
  5.should respond_to(:random_consonants)
41
46
  end
42
-
47
+
48
+ it "should be alias'd as random_consonant" do
49
+ Fixnum.instance_methods.should include("random_consonant")
50
+ 5.should respond_to(:random_consonant)
51
+ end
52
+
43
53
  it "should produce a string of random consonants" do
44
54
  [ 5, 10, 15, 25, 29 ].each do |i|
45
55
  str = i.random_consonants
@@ -77,6 +87,11 @@ describe Fixnum do
77
87
  5.should respond_to(:random_letters)
78
88
  end
79
89
 
90
+ it "should be alias'd as random_letter" do
91
+ Fixnum.instance_methods.should include("random_letter")
92
+ 5.should respond_to(:random_letter)
93
+ end
94
+
80
95
  it "should produce a string of random letters" do
81
96
  [ 5, 10, 15, 25, 29 ].each do |i|
82
97
  str = i.random_letters
@@ -113,6 +128,11 @@ describe Fixnum do
113
128
  5.should respond_to(:random_numbers)
114
129
  end
115
130
 
131
+ it "should be alias'd as random_number" do
132
+ Fixnum.instance_methods.should include("random_number")
133
+ 5.should respond_to(:random_number)
134
+ end
135
+
116
136
  it "should produce a string of random numbers" do
117
137
  [ 5, 10, 15, 25, 29 ].each do |i|
118
138
  num = i.random_numbers
@@ -187,6 +207,11 @@ describe Fixnum do
187
207
  5.should respond_to(:random_numbers)
188
208
  end
189
209
 
210
+ it "should be alias'd as random_character" do
211
+ Fixnum.instance_methods.should include("random_character")
212
+ 5.should respond_to(:random_character)
213
+ end
214
+
190
215
  it "should produce a string of random letters and numbers" do
191
216
  [ 5, 10, 15, 25, 29 ].each do |i|
192
217
  str = i.random_characters
@@ -219,4 +244,46 @@ describe Fixnum do
219
244
  end
220
245
  end
221
246
 
247
+
248
+ describe "random_hex_characters" do
249
+ it "should be a method" do
250
+ Fixnum.instance_methods.should include("random_hex_characters")
251
+ 5.should respond_to(:random_hex_character)
252
+ end
253
+
254
+ it "should be alias'd as random_hex_character" do
255
+ Fixnum.instance_methods.should include("random_hex_character")
256
+ 5.should respond_to(:random_hex_character)
257
+ end
258
+
259
+ it "should produce a string of random hex characters" do
260
+ [ 5, 10, 15, 25, 29, (26**2) ].each do |i|
261
+ str = i.random_hex_characters
262
+ str.should be_a_kind_of( String )
263
+ str.length.should == i
264
+ str.should match( /^[a-f0-9]+$/ )
265
+ end
266
+ end
267
+
268
+ it "should exclude a character" do
269
+ # 26^5 should be large enough to get at least one
270
+ # instance of every character.
271
+ str = (26**2).random_hex_characters(:except => "c")
272
+
273
+ str.should be_a_kind_of( String )
274
+ str.length.should == (26**2)
275
+ str.should_not match(/c/)
276
+ end
277
+
278
+ it "should exclude characters" do
279
+ # 26^5 should be large enough to get at least one
280
+ # instance of every character.
281
+ str = (26**2).random_hex_characters(:except => %w(c d f))
282
+
283
+ str.should be_a_kind_of( String )
284
+ str.length.should == (26**2)
285
+ str.should_not match(/cdf/)
286
+ end
287
+ end
288
+
222
289
  end
data/spec/range_spec.rb CHANGED
@@ -127,7 +127,23 @@ describe Range do
127
127
  str.should match( /^[a-z0-9]+$/ )
128
128
  end
129
129
  end
130
-
130
+
131
+ describe "#random_hex_characters" do
132
+ it "should be a method" do
133
+ Range.instance_methods.should include("random_hex_characters")
134
+ (0..1).should respond_to("random_hex_characters")
135
+ end
136
+
137
+ it "should generate a string of random hex characters" do
138
+ setup_range
139
+
140
+ str = @range.random_hex_characters
141
+ str.length.should == 4
142
+ str.should match(/^[a-f0-9]+$/)
143
+ end
144
+ end
145
+
146
+
131
147
  def setup_range
132
148
  @range = (3..5)
133
149
  @range.should_receive(:to_random_i).and_return(4)
data/tasks/rspec.rake CHANGED
@@ -16,9 +16,3 @@ To use rspec for testing you must install rspec gem:
16
16
  EOS
17
17
  exit(0)
18
18
  end
19
-
20
- desc "Run the specs under spec/*"
21
- Spec::Rake::SpecTask.new do |t|
22
- t.spec_opts = ["--options", "spec/spec.opts"]
23
- t.spec_files = FileList["spec/*_spec.rb"]
24
- end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rujitsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 3
10
+ version: 0.3.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Brightbox Systems Ltd
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-04 00:00:00 +00:00
18
+ date: 2010-06-03 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -31,10 +37,10 @@ extra_rdoc_files:
31
37
  - lib/rujitsu/object.rb
32
38
  - lib/rujitsu/range.rb
33
39
  - lib/rujitsu/string.rb
40
+ - lib/ujitsu.rb
34
41
  - tasks/rspec.rake
35
42
  files:
36
43
  - CHANGELOG
37
- - Manifest
38
44
  - README.rdoc
39
45
  - Rakefile
40
46
  - lib/rujitsu.rb
@@ -46,6 +52,7 @@ files:
46
52
  - lib/rujitsu/object.rb
47
53
  - lib/rujitsu/range.rb
48
54
  - lib/rujitsu/string.rb
55
+ - lib/ujitsu.rb
49
56
  - rujitsu.gemspec
50
57
  - spec/fixnum_spec.rb
51
58
  - spec/numeric_spec.rb
@@ -55,8 +62,9 @@ files:
55
62
  - spec/spec_helper.rb
56
63
  - spec/string_spec.rb
57
64
  - tasks/rspec.rake
65
+ - Manifest
58
66
  has_rdoc: true
59
- homepage: http://github.com/rahoub/rujitsu
67
+ homepage: http://github.com/brightbox/rujitsu
60
68
  licenses: []
61
69
 
62
70
  post_install_message:
@@ -70,21 +78,28 @@ rdoc_options:
70
78
  require_paths:
71
79
  - lib
72
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
73
82
  requirements:
74
83
  - - ">="
75
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
76
88
  version: "0"
77
- version:
78
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
79
91
  requirements:
80
92
  - - ">="
81
93
  - !ruby/object:Gem::Version
94
+ hash: 11
95
+ segments:
96
+ - 1
97
+ - 2
82
98
  version: "1.2"
83
- version:
84
99
  requirements: []
85
100
 
86
101
  rubyforge_project: rujitsu
87
- rubygems_version: 1.3.5
102
+ rubygems_version: 1.3.7
88
103
  signing_key:
89
104
  specification_version: 3
90
105
  summary: Various helper methods to smooth over Ruby development