rahoulb-rujitsu 0.1.4 → 0.1.5

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/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rujitsu', '0.1.4') do | config |
5
+ Echoe.new('rujitsu', '0.1.5') 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
@@ -1,74 +1,5 @@
1
- class Numeric
2
- # convert float values to "cents"
3
- # my_value = 2.5
4
- # my_value.to_cents # => 250
5
- def to_cents
6
- (self * 100.0).to_i
7
- end
8
- end
9
-
10
- class Fixnum
11
- # produce a string of N random letters
12
- # 5.random_letters
13
- def random_letters
14
- generate_random_string_using LETTERS
15
- end
16
- # produce a string of N random numbers
17
- # 5.random_numbers
18
- def random_numbers
19
- generate_random_string_using NUMBERS
20
- end
21
- # produce a string of N random characters
22
- # 5.random_characters
23
- def random_characters
24
- generate_random_string_using CHARACTERS
25
- end
26
-
27
- private
28
-
29
- LETTERS = ('a'..'z').to_a
30
- NUMBERS = ('0'..'9').to_a
31
- CHARACTERS = LETTERS + NUMBERS
32
-
33
- def generate_random_string_using(legal_characters)
34
- upper_limit = legal_characters.size - 1
35
- (1..self).collect do |num|
36
- legal_characters[rand(upper_limit)]
37
- end.join
38
- end
39
- end
40
-
41
-
42
- class Range
43
- # pull a random element out of this range
44
- def to_random_i
45
- self.to_a.sort_by { rand }.first
46
- end
47
-
48
- # create a string of random letters whose length is one of the values in your range
49
- # (3..4).random_letters #�=> returns a string or 3 or 4 random letters
50
- def random_letters
51
- self.to_random_i.random_letters
52
- end
53
-
54
- # create a string of random numbers whose length is one of the values in your range
55
- # (3..4).random_numbers #�=> returns a string or 3 or 4 random numbers
56
- def random_numbers
57
- self.to_random_i.random_numbers
58
- end
59
-
60
- # create a string of random characters whose length is one of the values in your range
61
- # (3..4).random_characters #�=> returns a string or 3 or 4 random characters
62
- def random_characters
63
- self.to_random_i.random_characters
64
- end
65
-
66
- end
67
-
68
-
69
- class String
70
- # Return a string that can be used as part of a url
71
- def to_url
72
- self.downcase.gsub(/[^\-0-9a-z ]/, '').split.join('-')
73
- end
74
- end
1
+ base_dir = File.expand_path(File.dirname(__FILE__))
2
+ require base_dir + '/rujitsu/fixnum'
3
+ require base_dir + '/rujitsu/numeric'
4
+ require base_dir + '/rujitsu/range'
5
+ require base_dir + '/rujitsu/string'
@@ -0,0 +1,41 @@
1
+ class Fixnum
2
+ # produce a string of N random vowels
3
+ def random_vowels
4
+ generate_random_string_using VOWELS
5
+ end
6
+ # produce a string of N random consonants
7
+ def random_consonants
8
+ generate_random_string_using CONSONANTS
9
+ end
10
+ # produce a string of N random letters
11
+ # 5.random_letters
12
+ def random_letters
13
+ generate_random_string_using LETTERS
14
+ end
15
+ # produce a string of N random numbers
16
+ # 5.random_numbers
17
+ def random_numbers
18
+ generate_random_string_using NUMBERS
19
+ end
20
+ # produce a string of N random characters
21
+ # 5.random_characters
22
+ def random_characters
23
+ generate_random_string_using CHARACTERS
24
+ end
25
+
26
+ private
27
+
28
+ VOWELS = ['a', 'e', 'i', 'o', 'u']
29
+ LETTERS = ('a'..'z').to_a
30
+ CONSONANTS = LETTERS - VOWELS
31
+ NUMBERS = ('0'..'9').to_a
32
+ CHARACTERS = LETTERS + NUMBERS
33
+
34
+ def generate_random_string_using(legal_characters)
35
+ upper_limit = legal_characters.size - 1
36
+ (1..self).collect do |num|
37
+ legal_characters[rand(upper_limit)]
38
+ end.join
39
+ end
40
+ end
41
+
@@ -0,0 +1,8 @@
1
+ class Numeric
2
+ # convert float values to "cents"
3
+ # my_value = 2.5
4
+ # my_value.to_cents # => 250
5
+ def to_cents
6
+ (self * 100.0).to_i
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ class Range
2
+ # pull a random element out of this range
3
+ def to_random_i
4
+ self.to_a.sort_by { rand }.first
5
+ end
6
+
7
+ # create a string of random letters whose length is one of the values in your range
8
+ # (3..4).random_letters # => returns a string or 3 or 4 random letters
9
+ def random_letters
10
+ self.to_random_i.random_letters
11
+ end
12
+
13
+ # create a string of random numbers whose length is one of the values in your range
14
+ # (3..4).random_numbers # => returns a string or 3 or 4 random numbers
15
+ def random_numbers
16
+ self.to_random_i.random_numbers
17
+ end
18
+
19
+ # create a string of random characters whose length is one of the values in your range
20
+ # (3..4).random_characters # => returns a string or 3 or 4 random characters
21
+ def random_characters
22
+ self.to_random_i.random_characters
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,6 @@
1
+ class String
2
+ # Return a string that can be used as part of a url
3
+ def to_url
4
+ self.downcase.gsub(/[^\-0-9a-z ]/, '').split.join('-')
5
+ end
6
+ 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.4"
5
+ s.version = "0.1.5"
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-11-28}
9
+ s.date = %q{2008-12-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", "lib/rujitsu/grammar.rb", "lib/rujitsu.rb", "README.rdoc", "tasks/rspec.rake"]
13
- s.files = ["CHANGELOG", "lib/rujitsu/grammar.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"]
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
+ 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
15
  s.homepage = %q{http://github.com/rahoub/rujitsu}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
data/spec/fixnum_spec.rb CHANGED
@@ -2,6 +2,38 @@ require File.join(File.dirname(__FILE__) + "/spec_helper")
2
2
 
3
3
  describe Fixnum do
4
4
 
5
+ describe "random_vowels" do
6
+ it "should be a method" do
7
+ Fixnum.instance_methods.should include("random_vowels")
8
+ 5.should respond_to(:random_vowels)
9
+ end
10
+
11
+ it "should produce a string of random vowels" do
12
+ [ 5, 10, 15, 25, 29 ].each do |i|
13
+ str = i.random_vowels
14
+ str.should be_a_kind_of( String )
15
+ str.length.should == i
16
+ str.should match( /^[aeiou]+$/ )
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "random_consonants" do
22
+ it "should be a method" do
23
+ Fixnum.instance_methods.should include("random_consonants")
24
+ 5.should respond_to(:random_consonants)
25
+ end
26
+
27
+ it "should produce a string of random consonants" do
28
+ [ 5, 10, 15, 25, 29 ].each do |i|
29
+ str = i.random_consonants
30
+ str.should be_a_kind_of( String )
31
+ str.length.should == i
32
+ str.should match( /^[bcdfghjklmnpqrstvwxyz]+$/ )
33
+ end
34
+ end
35
+ end
36
+
5
37
  describe "random_letters" do
6
38
  it "should be a method" do
7
39
  Fixnum.instance_methods.should include("random_letters")
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
4
+ version: 0.1.5
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-11-28 00:00:00 -08:00
12
+ date: 2008-12-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,13 +21,21 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - CHANGELOG
24
+ - lib/rujitsu/fixnum.rb
24
25
  - lib/rujitsu/grammar.rb
26
+ - lib/rujitsu/numeric.rb
27
+ - lib/rujitsu/range.rb
28
+ - lib/rujitsu/string.rb
25
29
  - lib/rujitsu.rb
26
30
  - README.rdoc
27
31
  - tasks/rspec.rake
28
32
  files:
29
33
  - CHANGELOG
34
+ - lib/rujitsu/fixnum.rb
30
35
  - lib/rujitsu/grammar.rb
36
+ - lib/rujitsu/numeric.rb
37
+ - lib/rujitsu/range.rb
38
+ - lib/rujitsu/string.rb
31
39
  - lib/rujitsu.rb
32
40
  - Manifest
33
41
  - Rakefile