Skip to content

Commit 5245e8f

Browse files
author
Edward Ocampo-Gooding
committed
Klunking together gem stuff
1 parent 28f3df4 commit 5245e8f

File tree

9 files changed

+80352
-0
lines changed

9 files changed

+80352
-0
lines changed

.document

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README.rdoc
2+
lib/**/*.rb
3+
bin/*
4+
features/**/*.feature
5+
LICENSE

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.sw?
2+
.DS_Store
3+
coverage
4+
rdoc
5+
pkg

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2009 Edward Ocampo-Gooding
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.rdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= auto-emo
2+
3+
Sometimes, you just need a whole lot of generated emo poetry.
4+
5+
Poems were filched from across the web. No more than a single line from each appears in any generated stanza. So, the marshalled poems are definitely not copyrighted by me, but everything else is.
6+
7+
== Copyright
8+
9+
Copyright (c) 2009 Edward Ocampo-Gooding. See LICENSE for details.

Rakefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'rubygems'
2+
require 'rake'
3+
4+
begin
5+
require 'jeweler'
6+
Jeweler::Tasks.new do |gem|
7+
gem.name = "auto-emo"
8+
gem.summary = %Q{Sometimes, you just need a whole lot of generated emo poetry}
9+
gem.email = "[email protected]"
10+
gem.homepage = "http://github.com/edward/auto-emo"
11+
gem.authors = ["Edward Ocampo-Gooding"]
12+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13+
end
14+
15+
rescue LoadError
16+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17+
end
18+
19+
require 'rake/testtask'
20+
Rake::TestTask.new(:test) do |test|
21+
test.libs << 'lib' << 'test'
22+
test.pattern = 'test/**/*_test.rb'
23+
test.verbose = true
24+
end
25+
26+
begin
27+
require 'rcov/rcovtask'
28+
Rcov::RcovTask.new do |test|
29+
test.libs << 'test'
30+
test.pattern = 'test/**/*_test.rb'
31+
test.verbose = true
32+
end
33+
rescue LoadError
34+
task :rcov do
35+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36+
end
37+
end
38+
39+
40+
task :default => :test
41+
42+
require 'rake/rdoctask'
43+
Rake::RDocTask.new do |rdoc|
44+
if File.exist?('VERSION.yml')
45+
config = YAML.load(File.read('VERSION.yml'))
46+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47+
else
48+
version = ""
49+
end
50+
51+
rdoc.rdoc_dir = 'rdoc'
52+
rdoc.title = "auto-emo #{version}"
53+
rdoc.rdoc_files.include('README*')
54+
rdoc.rdoc_files.include('lib/**/*.rb')
55+
end
56+

lib/auto-emo.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Created by Edward Ocampo-Gooding on 2007-01-31.
4+
5+
require "rubygems"
6+
require "progressbar"
7+
8+
# It would be really cool to have UTF8 working
9+
# require 'jcode'
10+
# $KCODE = 'UTF8'
11+
12+
# Returns a poem
13+
def poetry_churn(poems)
14+
length = 4 + rand(7)
15+
lines = []
16+
17+
length.times do
18+
lines << poems[rand(poems.size)]
19+
end
20+
21+
lines.join("\n")
22+
end
23+
24+
poems = []
25+
26+
File.open("marshalled_poems") do |f|
27+
poems = Marshal.load(f)
28+
end
29+
30+
if poems.empty?
31+
poem_file = File.open("poems.txt")
32+
poems_size = `wc poems.txt`.scan(/\w+/).first.to_i
33+
pbar = ProgressBar.new("PoemGrinding", poems_size)
34+
poem_file.each do |line|
35+
poems << line
36+
pbar.inc
37+
end
38+
end
39+
40+
File.open("marshalled_poems", 'w') do |f|
41+
Marshal.dump(poems, f)
42+
end
43+
44+
cleaned_poems = []
45+
46+
poems.each do |line|
47+
l = line.gsub(/<.*>/, ' ').gsub('&nbsp;', ' ').gsub("&quot;", '’')
48+
l = l.gsub("í", "'").gsub("Ö", '').squeeze(" ").strip
49+
next if l.size > 80
50+
next if l.size < 3
51+
next if l == "End of Poem"
52+
next if l =~ /^Author:/
53+
next if l =~ /^Title:/
54+
cleaned_poems << l
55+
end
56+
57+
puts "\nBooyeah! Let's make some poetry!"
58+
59+
pbar = ProgressBar.new("PoemGrinding", 500)
60+
61+
File.open("emo-poetry.txt", "w+") do |f|
62+
500.times do
63+
f << poetry_churn(cleaned_poems)
64+
f << "\n\n"
65+
pbar.inc
66+
end
67+
end
68+
69+
`open emo-poetry.txt`

0 commit comments

Comments
 (0)