rahoulb-rujitsu 0.1.1 → 0.1.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ = Version 0.1.3 (2008-11-24)
2
+
3
+ Cleaned up invalid characters
4
+ Refactored generate_random_string_using method
5
+
6
+ = Version 0.1.2 (2008-11-24)
7
+
8
+ Added full test suite
9
+
1
10
  = Version 0.1.1 (2008-11-22)
2
11
 
3
12
  Added range based random character generation
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rujitsu', '0.1.1') do | config |
5
+ Echoe.new('rujitsu', '0.1.3') 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'
data/lib/rujitsu.rb CHANGED
@@ -30,37 +30,35 @@ class Fixnum
30
30
  NUMBERS = ('0'..'9').to_a
31
31
  CHARACTERS = LETTERS + NUMBERS
32
32
 
33
- def generate_random_string_using legal_characters
34
- result = ""
33
+ def generate_random_string_using(legal_characters)
35
34
  upper_limit = legal_characters.size - 1
36
- self.times do | num |
37
- result << legal_characters[rand(upper_limit)]
38
- end
39
- return result
35
+ (1..self).collect do |num|
36
+ legal_characters[rand(upper_limit)]
37
+ end.join
40
38
  end
41
39
  end
42
40
 
43
41
 
44
42
  class Range
45
- #�pull a random element out of this range
43
+ # pull a random element out of this range
46
44
  def to_random_i
47
45
  self.to_a.sort_by { rand }.first
48
46
  end
49
47
 
50
48
  # create a string of random letters whose length is one of the values in your range
51
- #� (3..4).random_letters #�=> returns a string or 3 or 4 random letters
49
+ # (3..4).random_letters #�=> returns a string or 3 or 4 random letters
52
50
  def random_letters
53
51
  self.to_random_i.random_letters
54
52
  end
55
53
 
56
54
  # create a string of random numbers whose length is one of the values in your range
57
- #� (3..4).random_numbers #�=> returns a string or 3 or 4 random numbers
55
+ # (3..4).random_numbers #�=> returns a string or 3 or 4 random numbers
58
56
  def random_numbers
59
57
  self.to_random_i.random_numbers
60
58
  end
61
59
 
62
60
  # create a string of random characters whose length is one of the values in your range
63
- #� (3..4).random_characters #�=> returns a string or 3 or 4 random characters
61
+ # (3..4).random_characters #�=> returns a string or 3 or 4 random characters
64
62
  def random_characters
65
63
  self.to_random_i.random_characters
66
64
  end
data/rujitsu.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rujitsu}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.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
9
  s.date = %q{2008-11-24}
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", "lib/rujitsu.rb", "README.rdoc"]
13
- s.files = ["CHANGELOG", "lib/rujitsu.rb", "Manifest", "Rakefile", "README.rdoc", "rujitsu.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/rujitsu.rb", "README.rdoc", "tasks/rspec.rake"]
13
+ s.files = ["CHANGELOG", "lib/rujitsu.rb", "Manifest", "Rakefile", "README.rdoc", "rujitsu.gemspec", "spec/fixnum_spec.rb", "spec/numeric_spec.rb", "spec/range_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "tasks/rspec.rake"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/rahoub/rujitsu}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+ describe Fixnum do
4
+
5
+ describe "random_letters" do
6
+ it "should be a method" do
7
+ Fixnum.instance_methods.should include("random_letters")
8
+ 5.should respond_to(:random_letters)
9
+ end
10
+
11
+ it "should produce a string of random letters" do
12
+ [ 5, 10, 15, 25, 29 ].each do |i|
13
+ str = i.random_letters
14
+ str.should be_a_kind_of( String )
15
+ str.length.should == i
16
+ str.should match( /^[a-z]+$/ )
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "random_numbers" do
22
+ it "should be a method" do
23
+ Fixnum.instance_methods.should include("random_numbers")
24
+ 5.should respond_to(:random_numbers)
25
+ end
26
+
27
+ it "should produce a string of random numbers" do
28
+ [ 5, 10, 15, 25, 29 ].each do |i|
29
+ num = i.random_numbers
30
+ num.should be_a_kind_of( String )
31
+ num.length.should == i
32
+ num.should match( /^[0-9]+$/ )
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "random_characters" do
38
+ it "should be a method" do
39
+ Fixnum.instance_methods.should include("random_characters")
40
+ 5.should respond_to(:random_numbers)
41
+ end
42
+
43
+ it "should produce a string of random letters and numbers" do
44
+ [ 5, 10, 15, 25, 29 ].each do |i|
45
+ str = i.random_characters
46
+ str.should be_a_kind_of( String )
47
+ str.length.should == i
48
+ str.should match( /^[a-z0-9]+$/ )
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+ describe Numeric, "to_cents" do
4
+ it "should be a method" do
5
+ Numeric.instance_methods.should include("to_cents")
6
+ Numeric.new.should respond_to(:to_cents)
7
+ end
8
+
9
+ it "should convert float values to \"cents\"" do
10
+ [ 5, 10, 15, 25, 29 ].each do |i|
11
+ i.to_cents.should == (i*100).to_i
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+ describe Range do
4
+
5
+ describe "to_random_i" do
6
+ it "should be a method" do
7
+ Range.instance_methods.should include("to_random_i")
8
+ end
9
+
10
+ it "should return a random number from the range" do
11
+ # First check with an absolute
12
+ result = (3..3).to_random_i
13
+ result.should be_a_kind_of(Fixnum)
14
+ result.should == 3
15
+
16
+ # And then one that is random
17
+ res = (3..5).to_random_i
18
+ res.should be_a_kind_of(Fixnum)
19
+ [3,4,5].should include(res)
20
+ end
21
+ end
22
+
23
+ describe "random_letters" do
24
+ it "should be a method" do
25
+ Range.instance_methods.should include("random_letters")
26
+ (0..1).should respond_to(:random_letters)
27
+ end
28
+
29
+ it "should generate a string of random letters" do
30
+ setup_range
31
+
32
+ str = @range.random_letters
33
+ str.length.should == 4
34
+ str.should match( /^[a-z]+$/ )
35
+ end
36
+ end
37
+
38
+ describe "random_numbers" do
39
+ it "should be a method" do
40
+ Range.instance_methods.should include("random_numbers")
41
+ (0..1).should respond_to(:random_numbers)
42
+ end
43
+
44
+ it "should generate a string of random numbers" do
45
+ setup_range
46
+
47
+ str = @range.random_numbers
48
+ str.length.should == 4
49
+ str.should match( /^[0-9]+$/ )
50
+ end
51
+ end
52
+
53
+ describe "random_letters" do
54
+ it "should be a method" do
55
+ Range.instance_methods.should include("random_characters")
56
+ (0..1).should respond_to(:random_characters)
57
+ end
58
+
59
+ it "should generate a string of random letters" do
60
+ setup_range
61
+
62
+ str = @range.random_characters
63
+ str.length.should == 4
64
+ str.should match( /^[a-z0-9]+$/ )
65
+ end
66
+ end
67
+
68
+ def setup_range
69
+ @range = (3..5)
70
+ @range.should_receive(:to_random_i).and_return(4)
71
+ end
72
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__) + "/../lib/rujitsu")
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__) + "/spec_helper")
2
+
3
+ describe String, "to_url" do
4
+
5
+ it "should remove non-valid characters" do
6
+ "a!@£$".to_url.should == "a"
7
+ end
8
+
9
+ it "should convert spaces to hyphens" do
10
+ "a string".to_url.should == "a-string"
11
+ end
12
+
13
+ it "should downcase entire string" do
14
+ "THISISASTRING".to_url.should == "thisisastring"
15
+ end
16
+
17
+ it "should not touch [\\-0-9a-z]" do
18
+ "post-number-12345".to_url.should == "post-number-12345"
19
+ end
20
+
21
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,24 @@
1
+ # Borrowed from http://github.com/rsim/ruby-plsql/tree/master/tasks/rspec.rake
2
+ # Github++
3
+ begin
4
+ require "spec"
5
+ rescue LoadError
6
+ require "rubygems"
7
+ require "spec"
8
+ end
9
+
10
+ begin
11
+ require "spec/rake/spectask"
12
+ rescue LoadError
13
+ puts <<-EOS
14
+ To use rspec for testing you must install rspec gem:
15
+ [sudo] gem install rspec
16
+ EOS
17
+ exit(0)
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,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rahoulb-rujitsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brightbox Systems Ltd
@@ -23,6 +23,7 @@ extra_rdoc_files:
23
23
  - CHANGELOG
24
24
  - lib/rujitsu.rb
25
25
  - README.rdoc
26
+ - tasks/rspec.rake
26
27
  files:
27
28
  - CHANGELOG
28
29
  - lib/rujitsu.rb
@@ -30,6 +31,13 @@ files:
30
31
  - Rakefile
31
32
  - README.rdoc
32
33
  - rujitsu.gemspec
34
+ - spec/fixnum_spec.rb
35
+ - spec/numeric_spec.rb
36
+ - spec/range_spec.rb
37
+ - spec/spec.opts
38
+ - spec/spec_helper.rb
39
+ - spec/string_spec.rb
40
+ - tasks/rspec.rake
33
41
  has_rdoc: true
34
42
  homepage: http://github.com/rahoub/rujitsu
35
43
  post_install_message: