alexvollmer-word_salad 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ === 0.9.0 / 2008-09-09
2
+
3
+ * Happy Birthday Word Salad!
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/word_salad.rb
6
+ spec/word_salad_spec.rb
@@ -0,0 +1,58 @@
1
+ = Word Salad
2
+
3
+ == DESCRIPTION:
4
+
5
+ Word Salad is a very simple Ruby library for generating random strings
6
+ of English words based on the Unix dictionary file. The gems does its
7
+ best to figure out where your particular dictionary file is, but on
8
+ some systems may need a little help.
9
+
10
+ == SYNOPSIS:
11
+
12
+ Generating random data is helpful for all kinds of testing. You could
13
+ just generate random gobble-dee-gook, but why not generate something
14
+ that looks a bit English-like? If for no other reason, you'll find great
15
+ enjoyment in all of the potential band-names that this gem generates.
16
+
17
+ require 'rubygems'
18
+ require 'word_salad'
19
+
20
+ include WordSalad
21
+
22
+ words(3) ==> ['draw', 'ameliorate', 'bonanza']
23
+ sentences(2) ==> ['Shoot jonesing the make castle.', 'Blue murdered slight bastion.']
24
+ paragraphs(2) ==> []
25
+
26
+ WordSalad is a module, so including it in your class will activate
27
+ WordSalad's latent, random-generation super-powers in your class.
28
+
29
+ == INSTALL:
30
+
31
+ To install Word Salad, simply:
32
+
33
+ sudo gem install word_salad
34
+
35
+ == LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2008 Alex Vollmer
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/word_salad.rb'
6
+
7
+ Hoe.new('WordSalad', WordSalad::VERSION) do |p|
8
+ # p.rubyforge_name = 'WordSaladx' # if different than lowercase project name
9
+ p.name = 'word_salad'
10
+ p.developer('Alex Vollmer', 'alex.vollmer@gmail.com')
11
+ p.description = p.paragraphs_of('README.txt', 3..3).join("\n\n")
12
+ p.summary = 'Generate strings of random English text'
13
+ p.url = 'http://livollmers.net'
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.extra_dev_deps << ["rspec", ">=1.1.1"]
16
+ end
17
+
18
+ require "spec/rake/spectask"
19
+ Spec::Rake::SpecTask.new do |t|
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
22
+
23
+ # vim: syntax=Ruby
@@ -0,0 +1,51 @@
1
+ module WordSalad
2
+ VERSION = '0.9.0'
3
+
4
+ # Returns +num+ random words from the dictionary.
5
+ def words(num)
6
+ unless @dict
7
+ if FileTest.exists?("/usr/share/dict/words")
8
+ @dict = open("/usr/share/dict/words")
9
+ elsif FileTest.exists?("/usr/share/words")
10
+ @dict = open("/usr/share/words")
11
+ else
12
+ raise "No dictionary file found!"
13
+ end
14
+ @size = File.size(@dict)
15
+ end
16
+
17
+ (1..num).to_a.map do |x|
18
+ @dict.seek(rand(@size - 1000))
19
+ b = @dict.readchar
20
+ while b != 10
21
+ b = @dict.readchar
22
+ end
23
+
24
+ @dict.readline.strip
25
+ end
26
+ end
27
+
28
+ # Returns +num+ sentences of random words around +size+
29
+ # number of words.
30
+ def sentences(num, size=10)
31
+ variance = size / 5
32
+ (1..num).to_a.map do |x|
33
+ w = words(size + (rand(variance) - variance / 2))
34
+ w[0].capitalize!
35
+ w.join(' ') + '.'
36
+ end
37
+ end
38
+
39
+ # Returns +num+ paragraphs of around +psize+ sentences,
40
+ # each around +ssize+ number of words
41
+ def paragraphs(num, psize=5, ssize=10)
42
+ (1..num).to_a.map do |x|
43
+ sentences(psize).join(' ')
44
+ end
45
+ end
46
+
47
+ protected
48
+ def dictionary
49
+ # TODO: figure out all the places dictionary files go
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require File.join(File.dirname(__FILE__), "../lib/word_salad")
4
+
5
+ include WordSalad
6
+
7
+ describe WordSalad do
8
+ describe "generating random words" do
9
+ it "should return an array of the right size" do
10
+ w = words(5)
11
+ w.should be_kind_of(Array)
12
+ w.size.should eql(5)
13
+ w.each do |word|
14
+ word.should be_kind_of(String)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "generating random sentences" do
20
+ it "should return an array of sentences" do
21
+ s = sentences(5)
22
+ s.should be_kind_of(Array)
23
+ s.size.should == 5
24
+ s.each do |sent|
25
+ sent.should be_kind_of(String)
26
+ sent.should match(/^[A-Z].*\.$/)
27
+ sent.split(' ').size.should be_close(10, 2)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "generating random paragraphs" do
33
+ it "should return an array of paragraphs" do
34
+ p = paragraphs(5)
35
+ p.should be_kind_of(Array)
36
+ p.size.should == 5
37
+ p.each do |para|
38
+ para.should be_kind_of(String)
39
+ s = para.split('.')
40
+ s.size.should == 5
41
+ s.each do |sent|
42
+ sent.split(' ').size.should be_close(10, 2)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alexvollmer-word_salad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Vollmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.7.0
32
+ version:
33
+ description: "== SYNOPSIS:"
34
+ email:
35
+ - alex.vollmer@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - History.txt
42
+ - Manifest.txt
43
+ - README.txt
44
+ files:
45
+ - History.txt
46
+ - Manifest.txt
47
+ - README.txt
48
+ - Rakefile
49
+ - lib/word_salad.rb
50
+ - spec/word_salad_spec.rb
51
+ has_rdoc: true
52
+ homepage: http://livollmers.net
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --main
56
+ - README.txt
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project: wordsalad
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: Generate strings of random English text
78
+ test_files: []
79
+