rahoulb-rujitsu 0.1.5 → 0.1.6
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 +8 -0
- data/Rakefile +1 -1
- data/lib/rujitsu/fixnum.rb +14 -2
- data/rujitsu.gemspec +2 -2
- data/spec/fixnum_spec.rb +44 -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.1.
|
5
|
+
Echoe.new('rujitsu', '0.1.6') 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/fixnum.rb
CHANGED
@@ -14,8 +14,20 @@ class Fixnum
|
|
14
14
|
end
|
15
15
|
# produce a string of N random numbers
|
16
16
|
# 5.random_numbers
|
17
|
-
|
18
|
-
|
17
|
+
# optionally specific limits on the numbers
|
18
|
+
# 5.random_numbers(:from => 1, :to => 5)
|
19
|
+
def random_numbers( opts = {} )
|
20
|
+
# Then set some defaults, just in case
|
21
|
+
upper = opts[:to] || 9
|
22
|
+
lower = opts[:from] || 0
|
23
|
+
|
24
|
+
# And finally calculate the number
|
25
|
+
n = []
|
26
|
+
self.times do
|
27
|
+
i = (lower..upper).to_a.sort_by { rand }.first
|
28
|
+
n << i.to_s
|
29
|
+
end
|
30
|
+
n.join("")
|
19
31
|
end
|
20
32
|
# produce a string of N random characters
|
21
33
|
# 5.random_characters
|
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.1.
|
5
|
+
s.version = "0.1.6"
|
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{2008-12-
|
9
|
+
s.date = %q{2008-12-08}
|
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
@@ -64,6 +64,50 @@ describe Fixnum do
|
|
64
64
|
num.should match( /^[0-9]+$/ )
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
it "should contain only the number 5 upwards" do
|
69
|
+
num = 5.random_numbers(:from => 5)
|
70
|
+
|
71
|
+
num.should be_a_kind_of(String)
|
72
|
+
|
73
|
+
# Check each digit is greater than or equal to 5
|
74
|
+
string_to_integers(num).each do |i|
|
75
|
+
i.should be_a_kind_of(Integer)
|
76
|
+
i.should >= 5
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should contain on the number 5 downwards" do
|
81
|
+
num = 5.random_numbers(:to => 5)
|
82
|
+
|
83
|
+
num.should be_a_kind_of(String)
|
84
|
+
|
85
|
+
# Check each digit is lower than or equal to 5
|
86
|
+
string_to_integers(num).each do |i|
|
87
|
+
i.should be_a_kind_of(Integer)
|
88
|
+
i.should <= 5
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should contain numbers between 4 and 6" do
|
93
|
+
num = 5.random_numbers(:from => 4, :to => 6)
|
94
|
+
|
95
|
+
num.should be_a_kind_of(String)
|
96
|
+
|
97
|
+
# Check each digit is lower than or equal to 4..
|
98
|
+
# ..and greater than or equal to 6
|
99
|
+
string_to_integers(num).each do |i|
|
100
|
+
i.should be_a_kind_of(Integer)
|
101
|
+
i.should >= 4
|
102
|
+
i.should <= 6
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def string_to_integers(str)
|
109
|
+
str.split("").map {|x| x.to_i }
|
110
|
+
end
|
67
111
|
end
|
68
112
|
|
69
113
|
describe "random_characters" do
|
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.
|
4
|
+
version: 0.1.6
|
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: 2008-12-
|
12
|
+
date: 2008-12-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|