ruby_cowsay 0.1.0

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.
Files changed (54) hide show
  1. data/Manifest +53 -0
  2. data/README.mdown +79 -0
  3. data/Rakefile +13 -0
  4. data/lib/ruby_cowsay.rb +1 -0
  5. data/lib/ruby_cowsay/cow.rb +122 -0
  6. data/lib/ruby_cowsay/cows/beavis.zen.rb +27 -0
  7. data/lib/ruby_cowsay/cows/bong.rb +20 -0
  8. data/lib/ruby_cowsay/cows/bud-frogs.rb +16 -0
  9. data/lib/ruby_cowsay/cows/bunny.rb +14 -0
  10. data/lib/ruby_cowsay/cows/cheese.rb +27 -0
  11. data/lib/ruby_cowsay/cows/cower.rb +18 -0
  12. data/lib/ruby_cowsay/cows/daemon.rb +28 -0
  13. data/lib/ruby_cowsay/cows/default.rb +13 -0
  14. data/lib/ruby_cowsay/cows/dragon-and-cow.rb +25 -0
  15. data/lib/ruby_cowsay/cows/dragon.rb +25 -0
  16. data/lib/ruby_cowsay/cows/elephant-in-snake.rb +18 -0
  17. data/lib/ruby_cowsay/cows/elephant.rb +19 -0
  18. data/lib/ruby_cowsay/cows/eyes.rb +20 -0
  19. data/lib/ruby_cowsay/cows/flaming-sheep.rb +19 -0
  20. data/lib/ruby_cowsay/cows/ghostbusters.rb +30 -0
  21. data/lib/ruby_cowsay/cows/head-in.rb +16 -0
  22. data/lib/ruby_cowsay/cows/hellokitty.rb +15 -0
  23. data/lib/ruby_cowsay/cows/kiss.rb +30 -0
  24. data/lib/ruby_cowsay/cows/kitty.rb +16 -0
  25. data/lib/ruby_cowsay/cows/koala.rb +16 -0
  26. data/lib/ruby_cowsay/cows/kosh.rb +23 -0
  27. data/lib/ruby_cowsay/cows/luke-koala.rb +19 -0
  28. data/lib/ruby_cowsay/cows/mech-and-cow.rb +9 -0
  29. data/lib/ruby_cowsay/cows/meow.rb +19 -0
  30. data/lib/ruby_cowsay/cows/milk.rb +25 -0
  31. data/lib/ruby_cowsay/cows/moofasa.rb +18 -0
  32. data/lib/ruby_cowsay/cows/moose.rb +16 -0
  33. data/lib/ruby_cowsay/cows/mutilated.rb +14 -0
  34. data/lib/ruby_cowsay/cows/ren.rb +26 -0
  35. data/lib/ruby_cowsay/cows/satanic.rb +16 -0
  36. data/lib/ruby_cowsay/cows/sheep.rb +17 -0
  37. data/lib/ruby_cowsay/cows/skeleton.rb +18 -0
  38. data/lib/ruby_cowsay/cows/small.rb +13 -0
  39. data/lib/ruby_cowsay/cows/sodomized.rb +16 -0
  40. data/lib/ruby_cowsay/cows/stegosaurus.rb +23 -0
  41. data/lib/ruby_cowsay/cows/stimpy.rb +23 -0
  42. data/lib/ruby_cowsay/cows/supermilker.rb +14 -0
  43. data/lib/ruby_cowsay/cows/surgery.rb +28 -0
  44. data/lib/ruby_cowsay/cows/telebears.rb +16 -0
  45. data/lib/ruby_cowsay/cows/three-eyes.rb +14 -0
  46. data/lib/ruby_cowsay/cows/turkey.rb +30 -0
  47. data/lib/ruby_cowsay/cows/turtle.rb +24 -0
  48. data/lib/ruby_cowsay/cows/tux.rb +19 -0
  49. data/lib/ruby_cowsay/cows/udder.rb +18 -0
  50. data/lib/ruby_cowsay/cows/vader-koala.rb +20 -0
  51. data/lib/ruby_cowsay/cows/vader.rb +17 -0
  52. data/lib/ruby_cowsay/cows/www.rb +14 -0
  53. data/ruby_cowsay.gemspec +30 -0
  54. metadata +161 -0
data/Manifest ADDED
@@ -0,0 +1,53 @@
1
+ Manifest
2
+ README.mdown
3
+ Rakefile
4
+ lib/ruby_cowsay.rb
5
+ lib/ruby_cowsay/cow.rb
6
+ lib/ruby_cowsay/cows/beavis.zen.rb
7
+ lib/ruby_cowsay/cows/bong.rb
8
+ lib/ruby_cowsay/cows/bud-frogs.rb
9
+ lib/ruby_cowsay/cows/bunny.rb
10
+ lib/ruby_cowsay/cows/cheese.rb
11
+ lib/ruby_cowsay/cows/cower.rb
12
+ lib/ruby_cowsay/cows/daemon.rb
13
+ lib/ruby_cowsay/cows/default.rb
14
+ lib/ruby_cowsay/cows/dragon-and-cow.rb
15
+ lib/ruby_cowsay/cows/dragon.rb
16
+ lib/ruby_cowsay/cows/elephant-in-snake.rb
17
+ lib/ruby_cowsay/cows/elephant.rb
18
+ lib/ruby_cowsay/cows/eyes.rb
19
+ lib/ruby_cowsay/cows/flaming-sheep.rb
20
+ lib/ruby_cowsay/cows/ghostbusters.rb
21
+ lib/ruby_cowsay/cows/head-in.rb
22
+ lib/ruby_cowsay/cows/hellokitty.rb
23
+ lib/ruby_cowsay/cows/kiss.rb
24
+ lib/ruby_cowsay/cows/kitty.rb
25
+ lib/ruby_cowsay/cows/koala.rb
26
+ lib/ruby_cowsay/cows/kosh.rb
27
+ lib/ruby_cowsay/cows/luke-koala.rb
28
+ lib/ruby_cowsay/cows/mech-and-cow.rb
29
+ lib/ruby_cowsay/cows/meow.rb
30
+ lib/ruby_cowsay/cows/milk.rb
31
+ lib/ruby_cowsay/cows/moofasa.rb
32
+ lib/ruby_cowsay/cows/moose.rb
33
+ lib/ruby_cowsay/cows/mutilated.rb
34
+ lib/ruby_cowsay/cows/ren.rb
35
+ lib/ruby_cowsay/cows/satanic.rb
36
+ lib/ruby_cowsay/cows/sheep.rb
37
+ lib/ruby_cowsay/cows/skeleton.rb
38
+ lib/ruby_cowsay/cows/small.rb
39
+ lib/ruby_cowsay/cows/sodomized.rb
40
+ lib/ruby_cowsay/cows/stegosaurus.rb
41
+ lib/ruby_cowsay/cows/stimpy.rb
42
+ lib/ruby_cowsay/cows/supermilker.rb
43
+ lib/ruby_cowsay/cows/surgery.rb
44
+ lib/ruby_cowsay/cows/telebears.rb
45
+ lib/ruby_cowsay/cows/three-eyes.rb
46
+ lib/ruby_cowsay/cows/turkey.rb
47
+ lib/ruby_cowsay/cows/turtle.rb
48
+ lib/ruby_cowsay/cows/tux.rb
49
+ lib/ruby_cowsay/cows/udder.rb
50
+ lib/ruby_cowsay/cows/vader-koala.rb
51
+ lib/ruby_cowsay/cows/vader.rb
52
+ lib/ruby_cowsay/cows/www.rb
53
+ ruby_cowsay.gemspec
data/README.mdown ADDED
@@ -0,0 +1,79 @@
1
+ # Cowsay (In Ruby)
2
+
3
+ ___________
4
+ < OMGHI2U!! >
5
+ -----------
6
+ \ ^__^
7
+ \ (oo)\_______
8
+ (__)\ )\/\
9
+ ||----w |
10
+ || ||
11
+
12
+ ## What is this?
13
+
14
+ Cowsay on the command line is awesome. You can pipe stuff to it and it displays your message in a spectacular bovine fashion. What about when you want to use it in your log file or within a ruby application? Not so easy.
15
+
16
+ ## Until Now...
17
+
18
+ Using ruby_cowsay is easy. Here's some examples:
19
+
20
+ Simplest:
21
+
22
+ puts Cow.new.say('Mooooooooo!!!')
23
+ _______________
24
+ < Mooooooooo!!! >
25
+ ---------------
26
+ \ ^__^
27
+ \ (oo)\_______
28
+ (__)\ )\/\
29
+ ||----w |
30
+ || ||
31
+
32
+ Default Cow, Special Face
33
+
34
+ cow = Cow.new({ :face_type => 'paranoid'})
35
+ puts cow.say("Eveyone is staring at me!!!")
36
+ _____________________________
37
+ < Eveyone is staring at me!!! >
38
+ -----------------------------
39
+ \ ^__^
40
+ \ (@@)\_______
41
+ (__)\ )\/\
42
+ ||----w |
43
+ || ||
44
+
45
+ Using a Special Cow and a thinking bubble
46
+
47
+ steg = Cow.new({ :cow => 'stegosaurus' })
48
+ puts steg.say("My hat is so rad.", 'think')
49
+ ___________________
50
+ ( My hat is so rad. )
51
+ -------------------
52
+ o . .
53
+ o / `. .' "
54
+ o .---. < > < > .---.
55
+ o | \ \ - ~ ~ - / / |
56
+ _____ ..-~ ~-..-~
57
+ | | \~~~\.' `./~~~/
58
+ --------- \__/ \__/
59
+ .' O \ / / \ "
60
+ (_____, `._.' | } \/~~~/
61
+ `----. / } | / \__/
62
+ `-. | / | / `. ,~~|
63
+ ~-.__| /_ - ~ ^| /- _ `..-'
64
+ | / | / ~-. `-. _ _ _
65
+ |_____| |_____| ~ - . _ _ _ _ _>
66
+
67
+ ## Why Would I Use This?
68
+
69
+ Use it for whatever you want. I think it's nice for visually finding stuff you've injected into log files, dumping out console messages to users, or generally having fun.
70
+
71
+ ## Bugs
72
+
73
+ I'm sure there's bugs. I had to do things significantly different than the original implementation in order to achieve my goals here. If there's something you think I did poorly, by all means, fork, fix, and submit a pull request.
74
+
75
+ ## Special Thanks
76
+
77
+ I'd like to thank Tony Monroe for the original perl CLI implementation. You can find out more about that here:
78
+
79
+ http://www.nog.net/~tony/warez/cowsay.shtml
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('ruby_cowsay', '0.1.0') do |p|
6
+ p.description = 'Cowsay, written in ruby, as a gem.'
7
+ p.url = 'http://github.com/patricktulskie/cowsay'
8
+ p.author = 'Patrick Tulskie'
9
+ p.email = 'PatrickTulskie@gmail.com'
10
+ p.ignore_pattern = ['tmp/*', 'script/*', 'lib/main.rb', 'util/*', 'util/perl_cows/*']
11
+ end
12
+
13
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1 @@
1
+ require 'ruby_cowsay/cow'
@@ -0,0 +1,122 @@
1
+ class Cow
2
+
3
+ FACE_TYPES = {
4
+ 'default' => ["oo", " "],
5
+ 'borg' => ["==", " "],
6
+ 'dead' => ["==", "U "],
7
+ 'greedy' => ["$$", " "],
8
+ 'paranoid' => ["@@", " "],
9
+ 'stoned' => ["**", "U "],
10
+ 'tired' => ["--", " "],
11
+ 'wired' => ["OO", " "],
12
+ 'young' => ["..", " "]
13
+ }
14
+ MAX_LINE_LENGTH = 36
15
+
16
+ # ====================
17
+ # = Instance Methods =
18
+ # ====================
19
+
20
+ def initialize(options={})
21
+ cow_template = Cow.cows.include?(options[:cow]) ? options[:cow] : 'default'
22
+ require "#{File.expand_path(File.dirname(__FILE__))}/cows/#{cow_template}"
23
+ Cow.class_eval 'include CowTemplate'
24
+ face_type = Cow.faces.include?(options[:face_type]) ? options[:face_type] : 'default'
25
+ @eyes, @tongue = construct_face(options[:face_type])
26
+ end
27
+
28
+ def say(message, balloon_type = 'say')
29
+ construct_balloon(message, balloon_type) + "\n" + render_cow
30
+ end
31
+
32
+ # =================
33
+ # = Class Methods =
34
+ # =================
35
+ def self.faces
36
+ FACE_TYPES.keys.sort
37
+ end
38
+
39
+ def self.cows
40
+ Dir.new("#{File.expand_path(File.dirname(__FILE__))}/cows/").entries.inject([]) { |files, cow_file| files << cow_file.gsub('.rb', '') if cow_file =~ /\.rb/; files }
41
+ end
42
+
43
+ private
44
+
45
+ def construct_balloon(message, balloon_type)
46
+ balloon_lines = ""
47
+ @border = [] # up-left, up-right, down-left, down-right, left, right
48
+ if balloon_type == 'think'
49
+ @thoughts = 'o'
50
+ @border = %w{ ( ) ( ) ( ) }
51
+ elsif message.length < 36
52
+ @thoughts = '\\'
53
+ @border = %w{ < > }
54
+ else
55
+ @thoughts = '\\'
56
+ @border = %w{ / \\ \\ / | | }
57
+ end
58
+
59
+ formatted_message = format_message(message)
60
+ if formatted_message.length == 1
61
+ longest_line = formatted_message.first.length
62
+ @balloon_lines = " #{'_' * (longest_line + 2)} \n"
63
+ @balloon_lines << "#{@border.first} #{formatted_message.first} #{@border.last}\n"
64
+ @balloon_lines << " #{'-' * (longest_line + 2)} "
65
+ else
66
+ longest_line = formatted_message.map { |line| line.length }.sort.last
67
+ @balloon_lines = " #{'_' * (longest_line + 2)} \n"
68
+ formatted_message.each_with_index do |line, index|
69
+ case index
70
+ when 0; left, right = @border[0], @border[1]
71
+ when (formatted_message.length - 1); left, right = @border[2], @border[3]
72
+ else; left, right = @border[4], @border[5]
73
+ end
74
+ @balloon_lines << "#{left} #{line}#{' ' * (longest_line - line.length)} #{right}\n"
75
+ end
76
+ @balloon_lines << " #{'-' * (longest_line + 2)} "
77
+ end
78
+
79
+ return @balloon_lines
80
+ end
81
+
82
+ def construct_face(type = 'default')
83
+ FACE_TYPES[type || 'default']
84
+ end
85
+
86
+ def format_message(message)
87
+ message_lines = []
88
+ if message.length > MAX_LINE_LENGTH
89
+ words, line = message.split, ""
90
+ for word in words
91
+ if line.length > 0 && (line.length + word.length) > MAX_LINE_LENGTH
92
+ message_lines << line
93
+ line = ""
94
+ end
95
+ if word.length > MAX_LINE_LENGTH
96
+ broken_word = split_word(word)
97
+ line = broken_word.pop
98
+ message_lines = message_lines.concat(broken_word)
99
+ elsif line.length == 0
100
+ line = word
101
+ else
102
+ line = "#{line} #{word}"
103
+ end
104
+ end
105
+ message_lines << line
106
+ else
107
+ message_lines << message
108
+ end
109
+
110
+ return message_lines
111
+ end
112
+
113
+ def split_word(word)
114
+ return [word] unless word.length > MAX_LINE_LENGTH
115
+ lines = []
116
+ while word.length > 0 do
117
+ lines << word.slice!(0..(MAX_LINE_LENGTH - 1))
118
+ end
119
+ return lines.compact
120
+ end
121
+
122
+ end
@@ -0,0 +1,27 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts} __------~~-,
6
+ #{@thoughts} ,' ,
7
+ / \\
8
+ / :
9
+ | '
10
+ | |
11
+ | |
12
+ | _-- |
13
+ _| =-. .-. ||
14
+ o|/o/ _. |
15
+ / ~ \\ |
16
+ (____\@) ___~ |
17
+ |_===~~~.` |
18
+ _______.--~ |
19
+ \\________ |
20
+ \\ |
21
+ __/-___-- -__
22
+ / _ \\
23
+
24
+ COW
25
+ end
26
+
27
+ end
@@ -0,0 +1,20 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts}
6
+ #{@thoughts}
7
+ ^__^
8
+ _______/(#{@eyes})
9
+ /\\/( /(__)
10
+ | W----|| |~|
11
+ || || |~| ~~
12
+ |~| ~
13
+ |_| o
14
+ |#|/
15
+ _+#+_
16
+
17
+ COW
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts}
6
+ #{@thoughts}
7
+ oO)-. .-(Oo
8
+ /__ _\\ /_ __\\
9
+ \\ \\( | ()~() | )/ /
10
+ \\__|\\ | (-___-) | /|__/
11
+ ' '--' ==`-'== '--' '
12
+
13
+ COW
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts}
6
+ #{@thoughts} \\
7
+ \\ /\\
8
+ ( )
9
+ .( o ).
10
+
11
+ COW
12
+ end
13
+
14
+ end
@@ -0,0 +1,27 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts}
6
+ #{@thoughts}
7
+ _____ _________
8
+ / \\_/ |
9
+ | ||
10
+ | ||
11
+ | ###\\ /### | |
12
+ | 0 \\/ 0 | |
13
+ /| | |
14
+ / | < |\\ \\
15
+ | /| | | |
16
+ | | \\_______/ | | |
17
+ | | | / /
18
+ /|| /|||
19
+ ----------------|
20
+ | | | |
21
+ *** ***
22
+ /___\\ /___\\
23
+
24
+ COW
25
+ end
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts}
6
+ #{@thoughts}
7
+ ,__, | |
8
+ (oo)\\| |___
9
+ (__)\\| | )\\_
10
+ | |_w | \\
11
+ | | || *
12
+
13
+ Cower....
14
+
15
+ COW
16
+ end
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts} , ,
6
+ #{@thoughts} /( )`
7
+ #{@thoughts} \\ \\___ / |
8
+ /- _ `-/ '
9
+ (/\\/ \\ \\ /\\
10
+ / / | ` \\
11
+ O O ) / |
12
+ `-^--'`< '
13
+ (_.) _ ) /
14
+ `.___/` /
15
+ `-----' /
16
+ <----. __ / __ \\
17
+ <----|====O)))==) \\) /====
18
+ <----' `--' `.__,' \\
19
+ | |
20
+ \\ /
21
+ ______( (_ / \\______
22
+ ,' ,-----' | \\
23
+ `--{__________) \\/
24
+
25
+ COW
26
+ end
27
+
28
+ end
@@ -0,0 +1,13 @@
1
+ module CowTemplate
2
+
3
+ def render_cow
4
+ _ = <<COW
5
+ #{@thoughts} ^__^
6
+ #{@thoughts} (#{@eyes})\\_______
7
+ (__)\\ )\\/\\
8
+ #{@tongue} ||----w |
9
+ || ||
10
+ COW
11
+ end
12
+
13
+ end