random_text 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/random_text/random_strings.rb +16 -4
- data/lib/random_text/random_text.rb +8 -8
- data/lib/random_text.rb +1 -1
- data/random_text.gemspec +7 -7
- data/spec/random_text/random_string_spec.rb +22 -1
- data/spec/random_text/random_text_spec.rb +53 -10
- metadata +6 -7
data/Rakefile
CHANGED
@@ -9,5 +9,5 @@ require File.dirname(__FILE__) + '/lib/random_text'
|
|
9
9
|
Echoe.new('random_text', RandomText::VERSION) do |p|
|
10
10
|
p.author = "toy"
|
11
11
|
p.summary = "A library to generate random strings."
|
12
|
-
p.runtime_dependencies = ['activesupport
|
12
|
+
p.runtime_dependencies = ['activesupport']
|
13
13
|
end
|
@@ -1,12 +1,24 @@
|
|
1
1
|
module RandomText
|
2
2
|
class RandomStrings < Array
|
3
3
|
def get(count = nil)
|
4
|
-
|
4
|
+
case count
|
5
|
+
when :all
|
6
|
+
to_a.sort_by{ Kernel.rand }
|
7
|
+
when Integer
|
8
|
+
Array.new(count){ rand }
|
9
|
+
else
|
10
|
+
rand
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
|
-
def uniq(
|
8
|
-
|
9
|
-
|
14
|
+
def uniq(count)
|
15
|
+
case count
|
16
|
+
when :all
|
17
|
+
get(:all)
|
18
|
+
when Integer
|
19
|
+
raise "Dictionary has only #{length} elements (you asked for n)" if count > length
|
20
|
+
get(:all).slice(0, count)
|
21
|
+
end
|
10
22
|
end
|
11
23
|
end
|
12
24
|
end
|
@@ -2,27 +2,27 @@ module RandomText
|
|
2
2
|
class RandomText
|
3
3
|
def initialize(text)
|
4
4
|
@words = RandomStrings.new(text.scan(/\w{3,}/).collect{ |w| w.mb_chars.downcase.to_s }.reject{ |w| w =~ /^[0-9]/ }.uniq.map(&:mb_chars))
|
5
|
-
@sentences = RandomStrings.new(text.split(/[\r\n]+/).uniq)
|
5
|
+
@sentences = RandomStrings.new(text.split(/[\r\n]+/).map(&:strip).compact.delete_if(&:blank?).uniq)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def word
|
9
9
|
@words.get
|
10
10
|
end
|
11
|
-
|
12
|
-
def words(n)
|
11
|
+
|
12
|
+
def words(n = :all)
|
13
13
|
@words.get(n)
|
14
14
|
end
|
15
|
-
|
16
|
-
def uniq_words(n)
|
15
|
+
|
16
|
+
def uniq_words(n = :all)
|
17
17
|
@words.uniq(n)
|
18
18
|
end
|
19
19
|
alias_method :unique_words, :uniq_words
|
20
|
-
|
20
|
+
|
21
21
|
def sentence
|
22
22
|
@sentences.get
|
23
23
|
end
|
24
24
|
|
25
|
-
def sentences(n)
|
25
|
+
def sentences(n = :all)
|
26
26
|
@sentences.get(n)
|
27
27
|
end
|
28
28
|
end
|
data/lib/random_text.rb
CHANGED
data/random_text.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{random_text}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.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 = ["toy"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-04-22}
|
10
10
|
s.description = %q{A library to generate random strings.}
|
11
11
|
s.email = %q{}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/random_text/random_strings.rb", "lib/random_text/random_text.rb", "lib/random_text.rb", "README.rdoc", "tasks/rspec.rake"]
|
@@ -16,19 +16,19 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Random_text", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{random_text}
|
19
|
-
s.rubygems_version = %q{1.3.
|
19
|
+
s.rubygems_version = %q{1.3.2}
|
20
20
|
s.summary = %q{A library to generate random strings.}
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version =
|
24
|
+
s.specification_version = 3
|
25
25
|
|
26
26
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 0"
|
27
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
28
28
|
else
|
29
|
-
s.add_dependency(%q<activesupport>, [">= 0"
|
29
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
30
30
|
end
|
31
31
|
else
|
32
|
-
s.add_dependency(%q<activesupport>, [">= 0"
|
32
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
33
33
|
end
|
34
34
|
end
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
3
3
|
module RandomText
|
4
4
|
describe RandomStrings do
|
5
5
|
before :each do
|
6
|
-
@words = %w(Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua)
|
6
|
+
@words = %w(Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua lol)
|
7
7
|
@random_words = RandomStrings.new(@words)
|
8
8
|
end
|
9
9
|
|
@@ -27,6 +27,20 @@ module RandomText
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "with get(:all)" do
|
31
|
+
it "should return words" do
|
32
|
+
@random_words.get(:all).all?{ |w| w.should =~ /^\w+$/ }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return all words" do
|
36
|
+
@random_words.get(:all).sort.should == @words.sort
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return shuffled words" do
|
40
|
+
@random_words.get(:all).should_not == @random_words.get(:all)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
describe "with uniq(n)" do
|
31
45
|
it "should return words" do
|
32
46
|
@random_words.uniq(10).all?{ |w| w.should =~ /^\w+$/ }
|
@@ -40,5 +54,12 @@ module RandomText
|
|
40
54
|
@random_words.uniq(10).uniq.length.should == 10
|
41
55
|
end
|
42
56
|
end
|
57
|
+
|
58
|
+
describe "with uniq(:all)" do
|
59
|
+
it "should call get(:all)" do
|
60
|
+
@random_words.should_receive(:get).with(:all).and_return(:uniq_words)
|
61
|
+
@random_words.uniq(:all).should == :uniq_words
|
62
|
+
end
|
63
|
+
end
|
43
64
|
end
|
44
65
|
end
|
@@ -2,15 +2,58 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
2
2
|
|
3
3
|
module RandomText
|
4
4
|
describe RandomText do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
before :each do
|
6
|
+
@text = %Q{
|
7
|
+
Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.
|
8
|
+
Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius!
|
9
|
+
Claritas est etiam processus dynamicus, qui sequitur J.Brahmes mutationem consuetudium lectorum?
|
10
|
+
Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
|
11
|
+
}
|
12
|
+
@lorem = RandomText.new(@text)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return word" do
|
16
|
+
@lorem.word.should =~ /^\w+$/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return n words" do
|
20
|
+
words = @lorem.words(5)
|
21
|
+
words.length.should == 5
|
22
|
+
words.each{ |word| word.should =~ /^\w+$/ }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return all words" do
|
26
|
+
words = @lorem.words
|
27
|
+
words.length.should == 39
|
28
|
+
words.each{ |word| word.should =~ /^\w+$/ }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return n uniq words" do
|
32
|
+
words = @lorem.uniq_words(30)
|
33
|
+
words.length.should == 30
|
34
|
+
words.uniq.should == words
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return all uniq words (it is same as all words)" do
|
38
|
+
words = @lorem.uniq_words
|
39
|
+
words.length.should == 39
|
40
|
+
words.uniq.should == words
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return sentence" do
|
44
|
+
@lorem.sentence.should =~ /\w+(\W\w+)+/
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return n sentences" do
|
48
|
+
sentences = @lorem.sentences(10)
|
49
|
+
sentences.length.should == 10
|
50
|
+
sentences.each{ |sentence| sentence.should =~ /\w+(\W\w+)+/ }
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return all sentences" do
|
54
|
+
sentences = @lorem.sentences
|
55
|
+
sentences.length.should == 4
|
56
|
+
sentences.each{ |sentence| sentence.should =~ /\w+(\W\w+)+/ }
|
57
|
+
end
|
15
58
|
end
|
16
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-22 00:00:00 +04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,9 +21,6 @@ dependencies:
|
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
|
-
- - "="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.2
|
27
24
|
version:
|
28
25
|
description: A library to generate random strings.
|
29
26
|
email: ""
|
@@ -60,6 +57,8 @@ files:
|
|
60
57
|
- random_text.gemspec
|
61
58
|
has_rdoc: true
|
62
59
|
homepage: ""
|
60
|
+
licenses: []
|
61
|
+
|
63
62
|
post_install_message:
|
64
63
|
rdoc_options:
|
65
64
|
- --line-numbers
|
@@ -85,9 +84,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
84
|
requirements: []
|
86
85
|
|
87
86
|
rubyforge_project: random_text
|
88
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.2
|
89
88
|
signing_key:
|
90
|
-
specification_version:
|
89
|
+
specification_version: 3
|
91
90
|
summary: A library to generate random strings.
|
92
91
|
test_files: []
|
93
92
|
|