rujitsu 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +17 -0
- data/CHANGELOG +5 -1
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.rdoc +8 -16
- data/Rakefile +4 -17
- data/lib/rujitsu.rb +3 -0
- data/lib/rujitsu/all.rb +2 -0
- data/lib/rujitsu/date.rb +28 -0
- data/lib/rujitsu/fixnum.rb +6 -4
- data/lib/rujitsu/grammar.rb +3 -2
- data/lib/rujitsu/inspect.rb +4 -2
- data/lib/rujitsu/numeric.rb +2 -0
- data/lib/rujitsu/object.rb +2 -0
- data/lib/rujitsu/range.rb +20 -19
- data/lib/rujitsu/string.rb +19 -17
- data/lib/ujitsu.rb +3 -1
- data/rujitsu.gemspec +22 -25
- metadata +92 -61
- data/Manifest +0 -23
- data/spec/fixnum_spec.rb +0 -289
- data/spec/numeric_spec.rb +0 -14
- data/spec/object_spec.rb +0 -27
- data/spec/range_spec.rb +0 -151
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -1
- data/spec/string_spec.rb +0 -99
- data/tasks/rspec.rake +0 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ffa903afb31f421a3a70aaa7be80493b96387122
|
4
|
+
data.tar.gz: 5ba97b21216fe755c46ad225fb34c048b1fc6d91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19cec8cd78a9a32fa031496e54c9a4a77b0497e4c8b234a800dd7810dd034fcb40b2081fc0e62800f49d81c4af9877bd0c4506a45e0f63a3bd33e0a6b65027d5
|
7
|
+
data.tar.gz: 1715b9a643c5598744eb059798d3c448803f343ec9483531cc528ba33aec6cf1fd16d44cf51da892513c19c29ed348b2ab834ac8376d00fdfd1da962e08cecb3
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= Version 0.4.0 (2017-05-02)
|
2
|
+
|
3
|
+
Added ::start_of_this_month, ::start_of_last_month and ::start_of_next_month for Date class (via @worldisaduck)
|
4
|
+
|
1
5
|
= Version 0.3.1 (2009-12-04)
|
2
6
|
|
3
7
|
rujitsu/grammar now raises the proper rule (one of the most important updates ever)
|
@@ -54,4 +58,4 @@ Added range based random character generation
|
|
54
58
|
|
55
59
|
= Version 0.1.0 (2008-11-22)
|
56
60
|
|
57
|
-
Initial Release; random character generation, URL-friendly strings.
|
61
|
+
Initial Release; random character generation, URL-friendly strings.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2008 Brightbox Systems Ltd
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -4,8 +4,10 @@ A ruby gem with various helper methods to smooth out your Ruby development.
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Add the following to your Gemfile
|
8
|
+
|
9
|
+
gem "rujitsu"
|
10
|
+
|
9
11
|
== Including
|
10
12
|
|
11
13
|
require "rujitsu"
|
@@ -17,16 +19,6 @@ For using in irb, there's a nice shortcut for you to use:
|
|
17
19
|
|
18
20
|
(This works because <tt>-r</tt> is the argument to require a file, and both 'ubygems.rb' and 'ujitsu.rb' exist.)
|
19
21
|
|
20
|
-
=== Rails
|
21
|
-
|
22
|
-
To require in rails 2.2, add the following to your <tt>environment.rb</tt> file.
|
23
|
-
|
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"
|
29
|
-
|
30
22
|
== Documentation
|
31
23
|
|
32
24
|
Run <tt>rake docs</tt> and open doc/index.html.
|
@@ -40,11 +32,11 @@ The Fixnum class has a couple of extensions allowing you to generate random stri
|
|
40
32
|
5.random_letters
|
41
33
|
5.random_numbers
|
42
34
|
5.random_characters
|
43
|
-
|
35
|
+
|
44
36
|
You can also generate a variable length string.
|
45
37
|
|
46
38
|
(3..5).random_letters
|
47
|
-
|
39
|
+
|
48
40
|
This generates a string of random letters whose length is 3, 4 or 5 characters.
|
49
41
|
|
50
42
|
<em>(All the above methods exist in the singular too. eg, <tt>1.random_letter</tt>)</em>
|
@@ -60,13 +52,13 @@ The String class has an extension that strips out URL-unfriendly characters.
|
|
60
52
|
The String class has an extension that truncates it to a customisable length with a customisable suffix.
|
61
53
|
|
62
54
|
"this is a string".truncate(:length => 15) # => "this is a st..."
|
63
|
-
|
55
|
+
|
64
56
|
=== Testing for inclusion within a container
|
65
57
|
|
66
58
|
As Rubyists we are all familiar with using include? to test if our variable is one of a number of values.
|
67
59
|
|
68
60
|
if ['hello', 'world'].include?(@my_value) ...
|
69
|
-
|
61
|
+
|
70
62
|
However, it doesn't read correctly. Rujitsu allows you to write the following as it reads much more like English.
|
71
63
|
|
72
64
|
if @my_value.in? ['hello', 'world'] ...
|
data/Rakefile
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'echoe'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
4
3
|
|
5
|
-
|
6
|
-
config.description = 'Various helper methods to smooth over Ruby development'
|
7
|
-
config.url = 'http://github.com/brightbox/rujitsu'
|
8
|
-
config.author = 'Brightbox Systems Ltd'
|
9
|
-
config.email = 'hello@brightbox.co.uk'
|
10
|
-
config.ignore_pattern = ['tmp/*', 'script/*']
|
11
|
-
config.development_dependencies = []
|
12
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
5
|
|
14
|
-
|
15
|
-
task :build => [:manifest, :build_gemspec]
|
16
|
-
|
17
|
-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each do | rake_file |
|
18
|
-
load rake_file
|
19
|
-
end
|
6
|
+
task :default => :spec
|
data/lib/rujitsu.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
base_dir = File.expand_path(File.dirname(__FILE__))
|
2
4
|
require base_dir + '/rujitsu/fixnum'
|
3
5
|
require base_dir + '/rujitsu/numeric'
|
4
6
|
require base_dir + '/rujitsu/range'
|
5
7
|
require base_dir + '/rujitsu/string'
|
6
8
|
require base_dir + '/rujitsu/object'
|
9
|
+
require base_dir + '/rujitsu/date'
|
data/lib/rujitsu/all.rb
CHANGED
data/lib/rujitsu/date.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module RujitsuDate
|
4
|
+
def start_of_this_month
|
5
|
+
today = self.today
|
6
|
+
self.new(today.year, today.month)
|
7
|
+
end
|
8
|
+
|
9
|
+
def start_of_last_month
|
10
|
+
today = self.today
|
11
|
+
if today.month == 1
|
12
|
+
self.new(today.year - 1, 12)
|
13
|
+
else
|
14
|
+
self.new(today.year, today.month - 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_of_next_month
|
19
|
+
today = self.today
|
20
|
+
if today.month < 12
|
21
|
+
self.new(today.year, today.month + 1)
|
22
|
+
else
|
23
|
+
self.new(today.year + 1, 1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Date.send(:extend, RujitsuDate)
|
data/lib/rujitsu/fixnum.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RujitsuFixnum
|
2
4
|
# produce a string of N random vowels
|
3
5
|
def random_vowels opts={}
|
@@ -27,9 +29,9 @@ module RujitsuFixnum
|
|
27
29
|
upper = opts[:to] || 9
|
28
30
|
lower = opts[:from] || 0
|
29
31
|
only = opts[:only] || :both
|
30
|
-
|
32
|
+
|
31
33
|
# And finally calculate the number
|
32
|
-
n = []
|
34
|
+
n = []
|
33
35
|
(self - 1).times do
|
34
36
|
i = (lower..upper).to_a.sort_by { rand }.first
|
35
37
|
n << i.to_s
|
@@ -73,7 +75,7 @@ module RujitsuFixnum
|
|
73
75
|
legal_characters.delete(char)
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
78
|
+
|
77
79
|
upper_limit = legal_characters.size - 1
|
78
80
|
|
79
81
|
srand # seed rand
|
@@ -81,7 +83,7 @@ module RujitsuFixnum
|
|
81
83
|
legal_characters[rand(upper_limit)]
|
82
84
|
end.join
|
83
85
|
end
|
84
|
-
|
86
|
+
|
85
87
|
def end_number_choices opt
|
86
88
|
case opt
|
87
89
|
when :even
|
data/lib/rujitsu/grammar.rb
CHANGED
data/lib/rujitsu/inspect.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Kernel
|
2
4
|
# If output is true then echo's,
|
3
|
-
# else just returns the name
|
5
|
+
# else just returns the name
|
4
6
|
def _cmd output=false
|
5
7
|
caller[0] =~ /`([^']*)'/
|
6
8
|
output ? p($1) : $1
|
@@ -13,7 +15,7 @@ module ExtendObject
|
|
13
15
|
def simple_methods
|
14
16
|
self.methods.sort - Object.methods
|
15
17
|
end
|
16
|
-
|
18
|
+
|
17
19
|
# Matches your search string against all
|
18
20
|
# methods and returns array
|
19
21
|
def grep_method match
|
data/lib/rujitsu/numeric.rb
CHANGED
data/lib/rujitsu/object.rb
CHANGED
data/lib/rujitsu/range.rb
CHANGED
@@ -1,33 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RujitsuRange
|
2
4
|
# pull a random element out of this range
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def to_random_i
|
6
|
+
self.to_a.sort_by { rand }.first
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# create a string of random letters whose length is one of the values in your range
|
10
|
+
# (3..4).random_letters # => returns a string or 3 or 4 random letters
|
11
|
+
def random_letters
|
12
|
+
self.to_random_i.random_letters
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# create a string of random numbers whose length is one of the values in your range
|
16
|
+
# (3..4).random_numbers # => returns a string or 3 or 4 random numbers
|
17
|
+
def random_numbers opts = {}
|
18
|
+
self.to_random_i.random_numbers opts
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
# create a string of random characters whose length is one of the values in your range
|
22
|
+
# (3..4).random_characters # => returns a string or 3 or 4 random characters
|
23
|
+
def random_characters
|
24
|
+
self.to_random_i.random_characters
|
25
|
+
end
|
24
26
|
|
25
27
|
# create a string of random hex characters whose length is one of the values in your range
|
26
28
|
# (3..4).random_hex_characters # => returns a string of 3 or 4 random hex characters
|
27
29
|
def random_hex_characters
|
28
30
|
self.to_random_i.random_hex_characters
|
29
31
|
end
|
30
|
-
|
31
32
|
end
|
32
33
|
|
33
34
|
Range.send(:include, RujitsuRange)
|
data/lib/rujitsu/string.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module RujitsuString
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
# Return a string that can be used as part of a url
|
5
|
+
# replaces basic "bad" characters with "-"
|
6
|
+
def to_url
|
7
|
+
self.downcase.gsub(/[^\-0-9a-z ]/, '').split.join('-')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Truncates a string to the specified length,
|
11
|
+
# and appends suffix if required
|
12
|
+
#
|
13
|
+
# Options:
|
14
|
+
# * +length+ length to truncate string to. Includes the suffix in the length. Default is 50.
|
15
|
+
# * +suffix+ suffix to append to truncated string. Pass "" or false for no suffix. Default is "...".
|
16
|
+
#
|
17
|
+
def truncate opts = {}
|
18
|
+
opts[:length] ||= 50
|
19
|
+
opts[:suffix] = opts.has_key?(:suffix) ? opts[:suffix] : "..."
|
20
|
+
opts[:suffix] ||= ""
|
19
21
|
opts[:length] -= (opts[:suffix].length+1)
|
20
22
|
if opts[:length] > 0
|
21
23
|
self.length > opts[:length] ? self[0..opts[:length]] + opts[:suffix] : self
|
data/lib/ujitsu.rb
CHANGED
data/rujitsu.gemspec
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rujitsu"
|
5
|
+
spec.version = "0.4.0"
|
6
|
+
spec.date = "2010-06-03"
|
7
|
+
spec.authors = ["Brightbox Systems Ltd", "Caius Durling", "Rahoul Baruah"]
|
8
|
+
spec.email = %q{hello@brightbox.co.uk}
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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", "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
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{rujitsu}
|
18
|
-
s.rubygems_version = %q{1.3.7}
|
19
|
-
s.summary = %q{Various helper methods to smooth over Ruby development}
|
10
|
+
spec.summary = %q{Various helper methods to smooth over Ruby development}
|
11
|
+
spec.description = %q{Various helper methods to smooth over Ruby development}
|
12
|
+
spec.homepage = %q{http://github.com/brightbox/rujitsu}
|
13
|
+
spec.license = "MIT"
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
s.specification_version = 3
|
15
|
+
spec.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"]
|
16
|
+
spec.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rujitsu", "--main", "README.rdoc"]
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "timecop"
|
30
27
|
end
|
metadata
CHANGED
@@ -1,31 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rujitsu
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 3
|
10
|
-
version: 0.3.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brightbox Systems Ltd
|
8
|
+
- Caius Durling
|
9
|
+
- Rahoul Baruah
|
14
10
|
autorequire:
|
15
|
-
bindir:
|
11
|
+
bindir: exe
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
date: 2010-06-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.12'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '10.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: timecop
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
22
71
|
description: Various helper methods to smooth over Ruby development
|
23
72
|
email: hello@brightbox.co.uk
|
24
73
|
executables: []
|
25
|
-
|
26
74
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
75
|
+
extra_rdoc_files:
|
29
76
|
- CHANGELOG
|
30
77
|
- README.rdoc
|
31
78
|
- lib/rujitsu.rb
|
@@ -38,13 +85,17 @@ extra_rdoc_files:
|
|
38
85
|
- lib/rujitsu/range.rb
|
39
86
|
- lib/rujitsu/string.rb
|
40
87
|
- lib/ujitsu.rb
|
41
|
-
|
42
|
-
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".travis.yml"
|
43
91
|
- CHANGELOG
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
44
94
|
- README.rdoc
|
45
95
|
- Rakefile
|
46
96
|
- lib/rujitsu.rb
|
47
97
|
- lib/rujitsu/all.rb
|
98
|
+
- lib/rujitsu/date.rb
|
48
99
|
- lib/rujitsu/fixnum.rb
|
49
100
|
- lib/rujitsu/grammar.rb
|
50
101
|
- lib/rujitsu/inspect.rb
|
@@ -54,54 +105,34 @@ files:
|
|
54
105
|
- lib/rujitsu/string.rb
|
55
106
|
- lib/ujitsu.rb
|
56
107
|
- rujitsu.gemspec
|
57
|
-
- spec/fixnum_spec.rb
|
58
|
-
- spec/numeric_spec.rb
|
59
|
-
- spec/object_spec.rb
|
60
|
-
- spec/range_spec.rb
|
61
|
-
- spec/spec.opts
|
62
|
-
- spec/spec_helper.rb
|
63
|
-
- spec/string_spec.rb
|
64
|
-
- tasks/rspec.rake
|
65
|
-
- Manifest
|
66
|
-
has_rdoc: true
|
67
108
|
homepage: http://github.com/brightbox/rujitsu
|
68
|
-
licenses:
|
69
|
-
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
70
112
|
post_install_message:
|
71
|
-
rdoc_options:
|
72
|
-
- --line-numbers
|
73
|
-
- --inline-source
|
74
|
-
- --title
|
113
|
+
rdoc_options:
|
114
|
+
- "--line-numbers"
|
115
|
+
- "--inline-source"
|
116
|
+
- "--title"
|
75
117
|
- Rujitsu
|
76
|
-
- --main
|
118
|
+
- "--main"
|
77
119
|
- README.rdoc
|
78
|
-
require_paths:
|
120
|
+
require_paths:
|
79
121
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
|
82
|
-
requirements:
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
83
124
|
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
version: "0"
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
|
-
requirements:
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
92
129
|
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
segments:
|
96
|
-
- 1
|
97
|
-
- 2
|
98
|
-
version: "1.2"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
99
132
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
rubygems_version: 1.3.7
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.6.10
|
103
135
|
signing_key:
|
104
|
-
specification_version:
|
136
|
+
specification_version: 4
|
105
137
|
summary: Various helper methods to smooth over Ruby development
|
106
138
|
test_files: []
|
107
|
-
|
data/Manifest
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
README.rdoc
|
3
|
-
Rakefile
|
4
|
-
lib/rujitsu.rb
|
5
|
-
lib/rujitsu/all.rb
|
6
|
-
lib/rujitsu/fixnum.rb
|
7
|
-
lib/rujitsu/grammar.rb
|
8
|
-
lib/rujitsu/inspect.rb
|
9
|
-
lib/rujitsu/numeric.rb
|
10
|
-
lib/rujitsu/object.rb
|
11
|
-
lib/rujitsu/range.rb
|
12
|
-
lib/rujitsu/string.rb
|
13
|
-
lib/ujitsu.rb
|
14
|
-
rujitsu.gemspec
|
15
|
-
spec/fixnum_spec.rb
|
16
|
-
spec/numeric_spec.rb
|
17
|
-
spec/object_spec.rb
|
18
|
-
spec/range_spec.rb
|
19
|
-
spec/spec.opts
|
20
|
-
spec/spec_helper.rb
|
21
|
-
spec/string_spec.rb
|
22
|
-
tasks/rspec.rake
|
23
|
-
Manifest
|
data/spec/fixnum_spec.rb
DELETED
@@ -1,289 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__) + "/spec_helper")
|
2
|
-
|
3
|
-
describe Fixnum do
|
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 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
|
-
|
16
|
-
it "should produce a string of random vowels" do
|
17
|
-
[ 5, 10, 15, 25, 29 ].each do |i|
|
18
|
-
str = i.random_vowels
|
19
|
-
str.should be_a_kind_of( String )
|
20
|
-
str.length.should == i
|
21
|
-
str.should match( /^[aeiou]+$/ )
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should exclude a character" do
|
26
|
-
# Given there are 5 vowels, 5^3 should
|
27
|
-
# contain at least one instance of every vowel
|
28
|
-
str = (5**3).random_vowels(:except => "a")
|
29
|
-
str.should be_a_kind_of( String )
|
30
|
-
str.length.should == 5**3
|
31
|
-
str.should_not match(/a/)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should exclude characters" do
|
35
|
-
str = (5**3).random_vowels(:except => %w(i o u))
|
36
|
-
str.should be_a_kind_of( String )
|
37
|
-
str.length.should == 5**3
|
38
|
-
str.should_not match(/iou/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "random_consonants" do
|
43
|
-
it "should be a method" do
|
44
|
-
Fixnum.instance_methods.should include("random_consonants")
|
45
|
-
5.should respond_to(:random_consonants)
|
46
|
-
end
|
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
|
-
|
53
|
-
it "should produce a string of random consonants" do
|
54
|
-
[ 5, 10, 15, 25, 29 ].each do |i|
|
55
|
-
str = i.random_consonants
|
56
|
-
|
57
|
-
str.should be_a_kind_of( String )
|
58
|
-
str.length.should == i
|
59
|
-
str.should match( /^[bcdfghjklmnpqrstvwxyz]+$/ )
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should exclude a character" do
|
64
|
-
# 26^5 should be large enough to get at least one
|
65
|
-
# instance of every character.
|
66
|
-
str = (26**2).random_consonants(:except => "c")
|
67
|
-
|
68
|
-
str.should be_a_kind_of( String )
|
69
|
-
str.length.should == (26**2)
|
70
|
-
str.should_not match(/c/)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should exclude characters" do
|
74
|
-
# 26^5 should be large enough to get at least one
|
75
|
-
# instance of every character.
|
76
|
-
str = (26**2).random_consonants(:except => %w(c d f))
|
77
|
-
|
78
|
-
str.should be_a_kind_of( String )
|
79
|
-
str.length.should == (26**2)
|
80
|
-
str.should_not match(/cdf/)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "random_letters" do
|
85
|
-
it "should be a method" do
|
86
|
-
Fixnum.instance_methods.should include("random_letters")
|
87
|
-
5.should respond_to(:random_letters)
|
88
|
-
end
|
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
|
-
|
95
|
-
it "should produce a string of random letters" do
|
96
|
-
[ 5, 10, 15, 25, 29 ].each do |i|
|
97
|
-
str = i.random_letters
|
98
|
-
str.should be_a_kind_of( String )
|
99
|
-
str.length.should == i
|
100
|
-
str.should match( /^[a-z]+$/ )
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should exclude a character" do
|
105
|
-
# 26^5 should be large enough to get at least one
|
106
|
-
# instance of every character.
|
107
|
-
str = (26**2).random_letters(:except => "d")
|
108
|
-
|
109
|
-
str.should be_a_kind_of( String )
|
110
|
-
str.length.should == (26**2)
|
111
|
-
str.should_not match(/d/)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should exclude characters" do
|
115
|
-
# 26^5 should be large enough to get at least one
|
116
|
-
# instance of every character.
|
117
|
-
str = (26**2).random_letters(:except => %w(c d f))
|
118
|
-
|
119
|
-
str.should be_a_kind_of( String )
|
120
|
-
str.length.should == (26**2)
|
121
|
-
str.should_not match(/cdf/)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "random_numbers" do
|
126
|
-
it "should be a method" do
|
127
|
-
Fixnum.instance_methods.should include("random_numbers")
|
128
|
-
5.should respond_to(:random_numbers)
|
129
|
-
end
|
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
|
-
|
136
|
-
it "should produce a string of random numbers" do
|
137
|
-
[ 5, 10, 15, 25, 29 ].each do |i|
|
138
|
-
num = i.random_numbers
|
139
|
-
num.should be_a_kind_of( String )
|
140
|
-
num.length.should == i
|
141
|
-
num.should match( /^[0-9]+$/ )
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should contain only the number 5 upwards" do
|
146
|
-
num = 5.random_numbers(:from => 5)
|
147
|
-
|
148
|
-
num.should be_a_kind_of(String)
|
149
|
-
|
150
|
-
# Check each digit is greater than or equal to 5
|
151
|
-
string_to_integers(num).each do |i|
|
152
|
-
i.should be_a_kind_of(Integer)
|
153
|
-
i.should >= 5
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should contain on the number 5 downwards" do
|
158
|
-
num = 5.random_numbers(:to => 5)
|
159
|
-
|
160
|
-
num.should be_a_kind_of(String)
|
161
|
-
|
162
|
-
# Check each digit is lower than or equal to 5
|
163
|
-
string_to_integers(num).each do |i|
|
164
|
-
i.should be_a_kind_of(Integer)
|
165
|
-
i.should <= 5
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should contain numbers between 4 and 6" do
|
170
|
-
num = 5.random_numbers(:from => 4, :to => 6)
|
171
|
-
|
172
|
-
num.should be_a_kind_of(String)
|
173
|
-
|
174
|
-
# Check each digit is lower than or equal to 4..
|
175
|
-
# ..and greater than or equal to 6
|
176
|
-
string_to_integers(num).each do |i|
|
177
|
-
i.should be_a_kind_of(Integer)
|
178
|
-
i.should >= 4
|
179
|
-
i.should <= 6
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should create an even number" do
|
184
|
-
num = 5.random_numbers(:only => :even)
|
185
|
-
|
186
|
-
num.should be_a_kind_of(String)
|
187
|
-
(num.to_i % 2).should == 0
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should create an odd number" do
|
191
|
-
num = 5.random_numbers(:only => :odd)
|
192
|
-
|
193
|
-
num.should be_a_kind_of(String)
|
194
|
-
(num.to_i % 2).should_not == 0
|
195
|
-
end
|
196
|
-
|
197
|
-
private
|
198
|
-
|
199
|
-
def string_to_integers(str)
|
200
|
-
str.split("").map {|x| x.to_i }
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe "random_characters" do
|
205
|
-
it "should be a method" do
|
206
|
-
Fixnum.instance_methods.should include("random_characters")
|
207
|
-
5.should respond_to(:random_numbers)
|
208
|
-
end
|
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
|
-
|
215
|
-
it "should produce a string of random letters and numbers" do
|
216
|
-
[ 5, 10, 15, 25, 29 ].each do |i|
|
217
|
-
str = i.random_characters
|
218
|
-
str.should be_a_kind_of( String )
|
219
|
-
str.length.should == i
|
220
|
-
str.should match( /^[a-z0-9]+$/ )
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
|
225
|
-
it "should exclude a character" do
|
226
|
-
# 26^5 should be large enough to get at least one
|
227
|
-
# instance of every character.
|
228
|
-
str = (26**2).random_characters(:except => "c")
|
229
|
-
|
230
|
-
str.should be_a_kind_of( String )
|
231
|
-
str.length.should == (26**2)
|
232
|
-
str.should_not match(/c/)
|
233
|
-
end
|
234
|
-
|
235
|
-
|
236
|
-
it "should exclude characters" do
|
237
|
-
# 26^5 should be large enough to get at least one
|
238
|
-
# instance of every character.
|
239
|
-
str = (26**2).random_characters(:except => %w(c d f))
|
240
|
-
|
241
|
-
str.should be_a_kind_of( String )
|
242
|
-
str.length.should == (26**2)
|
243
|
-
str.should_not match(/cdf/)
|
244
|
-
end
|
245
|
-
end
|
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
|
-
|
289
|
-
end
|
data/spec/numeric_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
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
|
data/spec/object_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__) + "/spec_helper")
|
2
|
-
|
3
|
-
describe Object do
|
4
|
-
describe "testing membership of a container" do
|
5
|
-
it "should report whether it is in an array of objects" do
|
6
|
-
@object = Object.new
|
7
|
-
@positive = [@object, Object.new, Object.new]
|
8
|
-
@negative = [Object.new, Object.new, Object.new]
|
9
|
-
|
10
|
-
@object.in?(@positive).should be_true
|
11
|
-
@object.in?(@negative).should be_false
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should report whether it is equal if given a non-container" do
|
15
|
-
@object = Object.new
|
16
|
-
@another = Object.new
|
17
|
-
|
18
|
-
@object.in?(@object).should be_true
|
19
|
-
@object.in?(@another).should be_false
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should not be a member of nil" do
|
23
|
-
@object = Object.new
|
24
|
-
@object.in?(nil).should be_false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/spec/range_spec.rb
DELETED
@@ -1,151 +0,0 @@
|
|
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
|
-
setup_range
|
12
|
-
|
13
|
-
# First check with an absolute
|
14
|
-
result = @range.to_random_i
|
15
|
-
result.should be_a_kind_of(Fixnum)
|
16
|
-
result.should == 4
|
17
|
-
|
18
|
-
# And then one that is random
|
19
|
-
res = (3..5).to_random_i
|
20
|
-
res.should be_a_kind_of(Fixnum)
|
21
|
-
[3,4,5].should include(res)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "random_letters" do
|
26
|
-
it "should be a method" do
|
27
|
-
Range.instance_methods.should include("random_letters")
|
28
|
-
(0..1).should respond_to(:random_letters)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should generate a string of random letters" do
|
32
|
-
setup_range
|
33
|
-
|
34
|
-
str = @range.random_letters
|
35
|
-
str.length.should == 4
|
36
|
-
str.should match( /^[a-z]+$/ )
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "random_numbers" do
|
41
|
-
it "should be a method" do
|
42
|
-
Range.instance_methods.should include("random_numbers")
|
43
|
-
(0..1).should respond_to(:random_numbers)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should generate a string of random numbers" do
|
47
|
-
setup_range
|
48
|
-
|
49
|
-
str = @range.random_numbers
|
50
|
-
str.length.should == 4
|
51
|
-
str.should match( /^[0-9]+$/ )
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should contain only the number 5 upwards" do
|
55
|
-
setup_range
|
56
|
-
|
57
|
-
str = @range.random_numbers :from => 5
|
58
|
-
str.should be_a_kind_of(String)
|
59
|
-
|
60
|
-
string_to_integers(str).each do |i|
|
61
|
-
i.should be_a_kind_of(Integer)
|
62
|
-
i.should >= 5
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should contain only the number 5 downwards" do
|
67
|
-
setup_range
|
68
|
-
|
69
|
-
str = @range.random_numbers :to => 5
|
70
|
-
str.should be_a_kind_of(String)
|
71
|
-
|
72
|
-
string_to_integers(str).each do |i|
|
73
|
-
i.should be_a_kind_of(Integer)
|
74
|
-
i.should <= 5
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should contain only numbers between 4 and 6" do
|
79
|
-
setup_range
|
80
|
-
|
81
|
-
str = @range.random_numbers :from => 4, :to => 6
|
82
|
-
str.should be_a_kind_of(String)
|
83
|
-
|
84
|
-
string_to_integers(str).each do |i|
|
85
|
-
i.should be_a_kind_of(Integer)
|
86
|
-
i.should >= 4
|
87
|
-
i.should <= 6
|
88
|
-
end
|
89
|
-
end
|
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
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def string_to_integers(str)
|
112
|
-
str.split("").map {|x| x.to_i }
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "random_letters" do
|
117
|
-
it "should be a method" do
|
118
|
-
Range.instance_methods.should include("random_characters")
|
119
|
-
(0..1).should respond_to(:random_characters)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should generate a string of random letters" do
|
123
|
-
setup_range
|
124
|
-
|
125
|
-
str = @range.random_characters
|
126
|
-
str.length.should == 4
|
127
|
-
str.should match( /^[a-z0-9]+$/ )
|
128
|
-
end
|
129
|
-
end
|
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
|
-
|
147
|
-
def setup_range
|
148
|
-
@range = (3..5)
|
149
|
-
@range.should_receive(:to_random_i).and_return(4)
|
150
|
-
end
|
151
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__) + "/../lib/rujitsu")
|
data/spec/string_spec.rb
DELETED
@@ -1,99 +0,0 @@
|
|
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
|
22
|
-
|
23
|
-
describe String, "truncate" do
|
24
|
-
|
25
|
-
it "should return shorter string unmodified with no params" do
|
26
|
-
str = 30.random_characters
|
27
|
-
# default length is 50
|
28
|
-
str.truncate.should == str
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return shorter string unmodified with length param" do
|
32
|
-
str = "0123456789" # length 10
|
33
|
-
trunced = str.truncate(:length => 30)
|
34
|
-
trunced.length.should == 10
|
35
|
-
trunced.should == str
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return shorter string unmodified with suffix param" do
|
39
|
-
str = "0123456789" # length 10
|
40
|
-
trunced = str.truncate(:suffix => "abcd")
|
41
|
-
trunced.length.should == 10
|
42
|
-
trunced.should == str
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should return shorter string unmodified with length and suffix params" do
|
46
|
-
str = "0123456789" # length 10
|
47
|
-
trunced = str.truncate(:length => 30, :suffix => "abcd")
|
48
|
-
trunced.length.should == 10
|
49
|
-
trunced.should == str
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should truncate longer string with no params" do
|
53
|
-
str = "this is a string with a really long length just to get above 50 characters"
|
54
|
-
# default length is 50
|
55
|
-
# default suffix is "..."
|
56
|
-
trunced = str.truncate
|
57
|
-
trunced.length.should == 50
|
58
|
-
trunced.should == "this is a string with a really long length just..."
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should truncate longer string with length param" do
|
62
|
-
str = "123456789123456789" # length 11
|
63
|
-
trunced = str.truncate(:length => 10)
|
64
|
-
trunced.length.should == 10
|
65
|
-
trunced.should == "1234567..."
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should truncate longer string with suffix param" do
|
69
|
-
str = "this is a string with a really long length just to get above 50 characters"
|
70
|
-
# default length is 50
|
71
|
-
trunced = str.truncate(:suffix => "..abc")
|
72
|
-
trunced.length.should == 50
|
73
|
-
trunced.should == "this is a string with a really long length ju..abc"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should truncate longer string with length and suffix param" do
|
77
|
-
str = "123456789123456789" # length 11
|
78
|
-
trunced = str.truncate(:length => 10, :suffix => "abde")
|
79
|
-
trunced.length.should == 10
|
80
|
-
trunced.should == "123456abde"
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should return truncated string with no suffix if suffix param is false" do
|
84
|
-
str = "this is a string with a really long length just to get above 50 characters"
|
85
|
-
# default length is 50
|
86
|
-
trunced = str.truncate(:suffix => false)
|
87
|
-
trunced.length.should == 50
|
88
|
-
trunced.should == "this is a string with a really long length just to"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should return a string of length specified even when the suffix is longer" do
|
92
|
-
str = "this is a string" # => 16
|
93
|
-
suff = "this is a longer string" # => 23
|
94
|
-
trunced = str.truncate(:suffix => suff, :length => 10)
|
95
|
-
trunced.should == "this is a "
|
96
|
-
trunced.length.should == 10
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
data/tasks/rspec.rake
DELETED
@@ -1,18 +0,0 @@
|
|
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
|