brightbox-rujitsu 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = Version 0.1.9 (2009-02-20)
2
+
3
+ Added specifying only even or odd random numbers
4
+
1
5
  = Version 0.1.8 (2009-01-24)
2
6
 
3
7
  Added String#truncate + matching specs
data/README.rdoc CHANGED
@@ -13,11 +13,14 @@ A ruby gem with various helper methods to smooth out your Ruby development.
13
13
 
14
14
  === Rails
15
15
 
16
- To require in rails 2.2, add the following to your +environment.rb+ file.
16
+ To require in rails 2.2, add the following to your <tt>environment.rb</tt> file.
17
17
 
18
18
  config.gem "brightbox-rujitsu", :lib => "rujitsu", :source => "http://gems.github.com"
19
19
  config.gem "brightbox-rujitsu", :lib => "rujitsu/grammar", :source => "http://gems.github.com"
20
20
 
21
+ == Documentation
22
+
23
+ Run <tt>rake docs</tt> and open doc/index.html.
21
24
 
22
25
  == Usage
23
26
 
@@ -31,7 +34,7 @@ The Fixnum class has a couple of extensions allowing you to generate random stri
31
34
 
32
35
  You can also generate a variable length string.
33
36
 
34
- (3..5).random_letters
37
+ (3..5).random_letters
35
38
 
36
39
  This generates a string of random letters whose length is 3, 4 or 5 characters.
37
40
 
@@ -49,7 +52,7 @@ The String class has an extension that truncates it to a customisable length wit
49
52
 
50
53
  === Grammar
51
54
 
52
- So far the grammar library just adds the method +should_recieve+ for rspec assertions. Use it to find out what it does!
55
+ So far the grammar library just adds the method <tt>should_recieve</tt> for rspec assertions. Use it to find out what it does!
53
56
 
54
57
 
55
58
  == Released under the MIT Licence
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.8') do | config |
5
+ Echoe.new('rujitsu', '0.1.9') 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'
@@ -20,13 +20,16 @@ class Fixnum
20
20
  # Then set some defaults, just in case
21
21
  upper = opts[:to] || 9
22
22
  lower = opts[:from] || 0
23
+ only = opts[:only] || :both
23
24
 
24
25
  # And finally calculate the number
25
26
  n = []
26
- self.times do
27
+ (self - 1).times do
27
28
  i = (lower..upper).to_a.sort_by { rand }.first
28
29
  n << i.to_s
29
30
  end
31
+ # add the last digit according to :only
32
+ n << end_number_choices(only).select {|x| (lower <= x) && (x <= upper) }.sort_by { rand }.first.to_s
30
33
  n.join("")
31
34
  end
32
35
  # produce a string of N random characters
@@ -42,6 +45,8 @@ class Fixnum
42
45
  CONSONANTS = LETTERS - VOWELS
43
46
  NUMBERS = ('0'..'9').to_a
44
47
  CHARACTERS = LETTERS + NUMBERS
48
+ EVENS = %w(0 2 4 6 8).map {|x| x.to_i }
49
+ ODDS = %w(1 3 5 7 9).map {|x| x.to_i }
45
50
 
46
51
  def generate_random_string_using(legal_characters)
47
52
  upper_limit = legal_characters.size - 1
@@ -49,5 +54,15 @@ class Fixnum
49
54
  legal_characters[rand(upper_limit)]
50
55
  end.join
51
56
  end
57
+
58
+ def end_number_choices opt
59
+ case opt
60
+ when :even
61
+ EVENS
62
+ when :odd
63
+ ODDS
64
+ else
65
+ EVENS | ODDS
66
+ end
67
+ end
52
68
  end
53
-
data/rujitsu.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rujitsu}
5
- s.version = "0.1.8"
5
+ s.version = "0.1.9"
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-01-24}
9
+ s.date = %q{2009-02-20}
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"]
13
13
  s.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", "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
- s.homepage = %q{http://github.com/brightbox/rujitsu}
15
+ s.homepage = %q{http://github.com/rahoub/rujitsu}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{rujitsu}
data/spec/fixnum_spec.rb CHANGED
@@ -103,6 +103,20 @@ describe Fixnum do
103
103
  end
104
104
  end
105
105
 
106
+ it "should create an even number" do
107
+ num = 5.random_numbers(:only => :even)
108
+
109
+ num.should be_a_kind_of(String)
110
+ (num.to_i % 2).should == 0
111
+ end
112
+
113
+ it "should create an odd number" do
114
+ num = 5.random_numbers(:only => :odd)
115
+
116
+ num.should be_a_kind_of(String)
117
+ (num.to_i % 2).should_not == 0
118
+ end
119
+
106
120
  private
107
121
 
108
122
  def string_to_integers(str)
data/spec/range_spec.rb CHANGED
@@ -88,6 +88,24 @@ describe Range do
88
88
  end
89
89
  end
90
90
 
91
+ it "should create an even number" do
92
+ setup_range
93
+
94
+ str = @range.random_numbers :only => :even
95
+
96
+ str.should be_a_kind_of(String)
97
+ (str.to_i % 2).should == 0
98
+ end
99
+
100
+ it "should create an odd number" do
101
+ setup_range
102
+
103
+ str = @range.random_numbers :only => :odd
104
+
105
+ str.should be_a_kind_of(String)
106
+ (str.to_i % 2).should_not == 0
107
+ end
108
+
91
109
  private
92
110
 
93
111
  def string_to_integers(str)
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.1.8
4
+ version: 0.1.9
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-01-24 00:00:00 -08:00
12
+ date: 2009-02-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -49,7 +49,7 @@ files:
49
49
  - spec/string_spec.rb
50
50
  - tasks/rspec.rake
51
51
  has_rdoc: true
52
- homepage: http://github.com/brightbox/rujitsu
52
+ homepage: http://github.com/rahoub/rujitsu
53
53
  post_install_message:
54
54
  rdoc_options:
55
55
  - --line-numbers