yodaism 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +10 -0
- data/bin/yodaism +8 -0
- data/lib/yodaism.rb +23 -0
- data/lib/yodaism/command.rb +42 -0
- data/lib/yodaism/config.rb +22 -0
- data/lib/yodaism/quote.rb +79 -0
- data/lib/yodaism/quotes/quotes.txt +78 -0
- data/lib/yodaism/version.rb +3 -0
- data/test/helper.rb +15 -0
- data/test/test_command.rb +38 -0
- data/test/test_quote.rb +24 -0
- data/yodaism.gemspec +26 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/yodaism
ADDED
data/lib/yodaism.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
7
|
+
|
8
|
+
require 'yodaism/version'
|
9
|
+
require 'yodaism/command'
|
10
|
+
require 'yodaism/config'
|
11
|
+
require 'yodaism/quote'
|
12
|
+
|
13
|
+
module Yodaism
|
14
|
+
extend self
|
15
|
+
|
16
|
+
def quote
|
17
|
+
@quote ||= Yodaism::Quote.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= Yodaism::Config.new
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Yodaism
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
def execute(*args)
|
5
|
+
command = args.shift
|
6
|
+
major = args.shift
|
7
|
+
minor = args.empty? ? nil : args.join(' ')
|
8
|
+
|
9
|
+
output(Yodaism.quote.random) unless command
|
10
|
+
parse_commands(command, major, minor)
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_commands(command, major, minor)
|
14
|
+
return ascii_yoda if command == "ascii"
|
15
|
+
return version if command == "version"
|
16
|
+
return help_yoda if command == "help"
|
17
|
+
end
|
18
|
+
|
19
|
+
def ascii_yoda
|
20
|
+
output(Yodaism.quote.ascii)
|
21
|
+
end
|
22
|
+
|
23
|
+
def help_yoda
|
24
|
+
text = %{
|
25
|
+
- yodaism: help ---------------------------------------------------
|
26
|
+
yodaism outputs a random yoda quote
|
27
|
+
yodaism ascii outputs a ascii yoda with a quote
|
28
|
+
yodaism version outputs the current version
|
29
|
+
}.gsub(/^ {8}/, '')
|
30
|
+
output text
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
output "You're running with yoda version #{Yodaism::VERSION}. Congrats!"
|
35
|
+
end
|
36
|
+
|
37
|
+
def output(s)
|
38
|
+
puts(s)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Yodaism
|
2
|
+
class Config
|
3
|
+
FILE = "lib/yodaism/quotes/quotes.txt"
|
4
|
+
attr_reader :quotes
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@quotes = {}
|
8
|
+
File.exists?(file) ? load_quotes_from_file : exit(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_quotes_from_file
|
12
|
+
f = File.new(file)
|
13
|
+
f.each { |line|
|
14
|
+
@quotes[f.lineno-1] = line
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def file
|
19
|
+
FILE
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Yodaism
|
2
|
+
class Quote
|
3
|
+
attr_accessor :quote_array
|
4
|
+
attr_accessor :word_limit
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@quotes = Yodaism.config.quotes
|
8
|
+
@@quote_array = Array.new
|
9
|
+
@@word_limit = 8
|
10
|
+
end
|
11
|
+
|
12
|
+
def random
|
13
|
+
r = Random.new
|
14
|
+
c = r.rand(0..@quotes.size - 1)
|
15
|
+
split_quote_text @quotes[c].strip
|
16
|
+
end
|
17
|
+
|
18
|
+
def ascii
|
19
|
+
quote_with_yoda random
|
20
|
+
end
|
21
|
+
|
22
|
+
def quote_with_yoda(yoda_quote)
|
23
|
+
yoda = %q{
|
24
|
+
.--.
|
25
|
+
::\`--._,'.::.`._.--'/:: 0
|
26
|
+
::::. ` __::__ ' .:::: 1
|
27
|
+
::::::-:.`'..`'.:-:::::: 2
|
28
|
+
::::::::\ `--' /:::::::: 3
|
29
|
+
:::::::::------::::::::: 4
|
30
|
+
5
|
31
|
+
6
|
32
|
+
7
|
33
|
+
8
|
34
|
+
|
35
|
+
}.gsub(/^ {10}/,'')
|
36
|
+
return replace_identifiers_with_quote_text yoda, yoda_quote
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace_identifiers_with_quote_text(text, yoda_quote)
|
40
|
+
#replaces the number from the template with a quote and
|
41
|
+
#also replaces any left over number with a blank string
|
42
|
+
#
|
43
|
+
index = 0
|
44
|
+
(0..8).each do |line_num|
|
45
|
+
replace_text = ""
|
46
|
+
if index <= yoda_quote.size
|
47
|
+
replace_text = yoda_quote[index] == nil ? "" : yoda_quote[index]
|
48
|
+
end
|
49
|
+
text = text.gsub(index.to_s, replace_text)
|
50
|
+
index += 1
|
51
|
+
end
|
52
|
+
return text
|
53
|
+
end
|
54
|
+
|
55
|
+
def split_quote_text(text)
|
56
|
+
text_array = text.split(" ")
|
57
|
+
size = text_array.size.divmod(@@word_limit)
|
58
|
+
populate_quote_array(text_array, size[0], size[1])
|
59
|
+
return @@quote_array
|
60
|
+
end
|
61
|
+
|
62
|
+
def populate_quote_array(text_array, lines, remainder)
|
63
|
+
limit = 0
|
64
|
+
(1..lines).each do | line_num |
|
65
|
+
put_text_in_array(text_array[limit, @@word_limit])
|
66
|
+
limit = @@word_limit * line_num
|
67
|
+
end
|
68
|
+
put_text_in_array(text_array[limit, remainder])
|
69
|
+
end
|
70
|
+
|
71
|
+
def put_text_in_array(word_array)
|
72
|
+
text = ""
|
73
|
+
word_array.each do |word|
|
74
|
+
text = text.empty? ? word : text + " " + word
|
75
|
+
end
|
76
|
+
@@quote_array.push(text)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Fear is the path to the dark side. Fear leads to anger, anger leads to hate, hate leads to suffering.
|
2
|
+
Confer on you, the level of Jedi Knight, the Council does. But, agree with your taking this boy as your Padawan Learner… I do not
|
3
|
+
Qui-Gon's defiance I sense in you. Need that you do not. Agree with you, the Council does. Your apprentice young Skywalker will be.
|
4
|
+
Lost a planet, Master Obi-Wan has. How embarrassing… how embarrassing.
|
5
|
+
Go to the center of the gravity's pull, and find your planet you will.
|
6
|
+
Meditate on this, I will.
|
7
|
+
Clear, your mind must be if you are to discover the real villains behind the plot.
|
8
|
+
Pain. Suffering. Death, I feel. Something terrible has happened. Young Skywalker is in pain. Terrible pain.
|
9
|
+
Around the survivors, a perimeter create!
|
10
|
+
Powerful you have become, Dooku. The dark side I sense in you.
|
11
|
+
Master Obi-Wan, not victory. The shroud of the dark side has fallen. Begun, the Clone War has!
|
12
|
+
Much to learn, you still have.
|
13
|
+
Like fire across the galaxy, the Clone Wars spread. In league with the wicked Count Dooku more and more planets slip. Upon the Jedi Knights falls the duty to lead the newly formed Army of the Republic.
|
14
|
+
Death is a natural part of life. Rejoice for those who transform into the Force. Mourn them do not. Miss them do not. Attachment leads to jealousy. The shadow of greed, that is.
|
15
|
+
Careful you must be when sensing the future. The fear of loss is a path to the dark side.
|
16
|
+
Train yourself to let go of everything you fear to lose.
|
17
|
+
Go, I will. Good relations with the Wookiees, I have.
|
18
|
+
Too much under the sway of the Chancellor, he is. Much anger there is in him. Too much pride in his powers.
|
19
|
+
If into the security recordings you go, only pain will you find.
|
20
|
+
Destroy the Sith, we must.
|
21
|
+
To fight this Lord Sidious, strong enough, you are not.
|
22
|
+
Twisted by the dark side, young Skywalker has become.
|
23
|
+
The boy you trained, gone he is, consumed by Darth Vader.
|
24
|
+
I hear a new apprentice you have, Emperor. Or should I call you Darth Sidious?
|
25
|
+
At an end your rule is… and not short enough it was.
|
26
|
+
Not if anything to say about it, I have!
|
27
|
+
Into exile I must go. Failed, I have.
|
28
|
+
If so powerful you are, why leave?
|
29
|
+
Faith in your new apprentice, misplaced may be. As is your faith in the dark side of the Force.
|
30
|
+
Looking? Found someone you have I would say, mm?
|
31
|
+
Help you I can! Yes! Mm!
|
32
|
+
Awww, cannot get your ship out…eh-heheheh!
|
33
|
+
How you get so big, eating food of this kind?
|
34
|
+
Mine! Or I will help you not!
|
35
|
+
Mudhole? Slimy? My home this is!
|
36
|
+
I cannot teach him. The boy has no patience.
|
37
|
+
Hmm. Much anger in him, like his father.
|
38
|
+
You will be. You will be.
|
39
|
+
Yes. A Jedi's strength flows from the Force. But beware the dark side. Anger, fear, aggression. The dark side of the Force are they. Easily they flow, quick to join you in a fight. If once you start down the dark path, forever will it dominate your destiny. Consume you it will, as it did Obi-Wan's apprentice.
|
40
|
+
You will know… when you are calm, at peace, passive. A Jedi uses the Force for knowledge and defense, never for attack.
|
41
|
+
So certain are you. Always with you it cannot be done. Hear you nothing that I say?
|
42
|
+
No! No different! Only different in your mind. You must unlearn what you have learned.
|
43
|
+
That is why you fail.
|
44
|
+
No! Try not. Do. Or do not. There is no try.
|
45
|
+
Size matters not. Look at me. Judge me by my size do you?
|
46
|
+
And well you should not! For my ally is the Force. And a powerful ally it is. Life creates it, makes it grow. Its energy surrounds us… and binds us. Luminous beings are we, not this… crude matter! You must feel the Force around you. Here, between you, me, the tree, the rock… everywhere! Even between the land and the ship.
|
47
|
+
Through the Force, things you will see. Other places. The future…the past…old friends long gone.
|
48
|
+
Hmm. Control, control. You must learn control.
|
49
|
+
Difficult to see. Always in motion is the future.
|
50
|
+
Decide you must how to serve them best. If you leave now, help them you could. But you would destroy all for which they have fought and suffered.
|
51
|
+
Mind what you have learned. Save you it can!
|
52
|
+
No. There is another.
|
53
|
+
When nine hundred years old you reach, look as good, you will not, hm?
|
54
|
+
Strong am I with the Force, but not that strong. Twilight is upon me, and soon night must fall. That is the way of things… the way of the Force.
|
55
|
+
No more training do you require. Already know you that which you need.
|
56
|
+
No. Unfortunate that you rushed to face him… that incomplete was your training. Not ready for the burden were you.
|
57
|
+
Remember, a Jedi's strength flows from the Force. But beware. Anger, fear, aggression. The dark side are they. Once you start down the dark path, forever will it dominate your destiny.
|
58
|
+
Your father he is.
|
59
|
+
Do not underestimate the powers of the Emperor, or suffer your father's fate, you will.
|
60
|
+
When gone am I, the last of the Jedi will you be.
|
61
|
+
Pity your new disciple I do; so lately an apprentice, so soon without a Master.
|
62
|
+
War does not make one great.
|
63
|
+
Proud I am, to stand by Wookiees in their hour of need.
|
64
|
+
Yoda I am, fight I will.
|
65
|
+
Tired I am, rest I must.
|
66
|
+
When all choices seem wrong, choose restraint.
|
67
|
+
If no mistake have you made, yet losing you are … a different game you should play.
|
68
|
+
A trial of being old is this: remembering which thing one has said into which young ears.
|
69
|
+
Think you I have never felt the touch of the dark? Know you what a soul so great as Yoda can make, in eight hundred years?
|
70
|
+
Think you the relationship between Master and Padawan is only to help them? Oh, this is what we let them believe, yes! But when the day comes that even old Yoda does not learn something from his students-then truly, he shall be a teacher no more.
|
71
|
+
On many long journeys have I gone. And waited, too, for others to return from journeys of their own. Some return; some are broken; some come back so different only their names remain.
|
72
|
+
Honor life by living, Padawan. Killing honors only death: only the dark side.
|
73
|
+
To be Jedi is to face the truth, and choose. Give off light, or darkness, Padawan. Be a candle, or the night, Padawan: but choose!
|
74
|
+
When you look at the dark side, careful you must be … for the dark side looks back.
|
75
|
+
You think Yoda stops teaching, just because his student does not want to hear? Yoda a teacher is. Yoda teaches like drunkards drink. Like killers kill.
|
76
|
+
A labyrinth of evil, this war has become.
|
77
|
+
To the Force, look for guidance. Accept what fate has placed before us.
|
78
|
+
My ally is the Force.
|
data/test/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
require 'redgreen'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'mocha'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
|
15
|
+
require 'yodaism'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Yodaism::Command
|
4
|
+
def self.capture_output
|
5
|
+
@output = ''
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.captured_output
|
9
|
+
@output
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.output(s)
|
13
|
+
@output << s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestCommand < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def command(cmd)
|
20
|
+
cmd = cmd.split(' ') if cmd
|
21
|
+
Yodaism::Command.capture_output
|
22
|
+
Yodaism::Command.execute(*cmd)
|
23
|
+
output = Yodaism::Command.captured_output
|
24
|
+
output.gsub(/\e\[\d\d?m/, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_version_switch
|
28
|
+
assert_match /#{Yodaism::VERSION}/, command('version')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_help_switch
|
32
|
+
assert_match 'yodaism: help', command('help')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_ascii_swtich
|
36
|
+
assert_match "::::::-:.`'..`'.:-::::::", command('ascii')
|
37
|
+
end
|
38
|
+
end
|
data/test/test_quote.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestQuote < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_split
|
7
|
+
quote = Yodaism::Quote.new
|
8
|
+
textArray = quote.split_quote_text("test should be split on new line when more then 5 words i wonder if it's just the remainder")
|
9
|
+
|
10
|
+
assert_equal 'test should be split on new line when', textArray[0]
|
11
|
+
assert_equal 'more then 5 words i wonder if it\'s', textArray[1]
|
12
|
+
assert_equal 'just the remainder', textArray[2]
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_replace_identifiers_with_quote_text
|
16
|
+
quote = Yodaism::Quote.new
|
17
|
+
textArray = quote.split_quote_text("test should be split on new line when more then 5 words i wonder if it's just the remainder")
|
18
|
+
|
19
|
+
indentifier_string = "0 : 1 : 2 : 3"
|
20
|
+
replaced_text = quote.replace_identifiers_with_quote_text(indentifier_string, textArray)
|
21
|
+
|
22
|
+
assert_equal 'test should be split on new line when : more then words i wonder if it\'s : just the remainder : ', replaced_text
|
23
|
+
end
|
24
|
+
end
|
data/yodaism.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yodaism/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yodaism"
|
7
|
+
s.version = Yodaism::VERSION
|
8
|
+
s.authors = ["willywos"]
|
9
|
+
s.email = ["wwilimek@gmail.com"]
|
10
|
+
s.homepage = "http://www.github.com/willywos"
|
11
|
+
s.summary = %q{Yodaism is about all things Yoda}
|
12
|
+
s.description = %q{Ever need a quick quote from Yoda?
|
13
|
+
Maybe you just need him to give you some quick advice.
|
14
|
+
Yodaism is a collection of quotes and some ascii porn to get your Yoda fix.}
|
15
|
+
|
16
|
+
s.rubyforge_project = "yodaism"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.executables = ["yodaism"]
|
23
|
+
s.default_executable = 'yodaism'
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yodaism
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- willywos
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-01-13 00:00:00 -06:00
|
18
|
+
default_executable: yodaism
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
description: |-
|
34
|
+
Ever need a quick quote from Yoda?
|
35
|
+
Maybe you just need him to give you some quick advice.
|
36
|
+
Yodaism is a collection of quotes and some ascii porn to get your Yoda fix.
|
37
|
+
email:
|
38
|
+
- wwilimek@gmail.com
|
39
|
+
executables:
|
40
|
+
- yodaism
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Rakefile
|
49
|
+
- bin/yodaism
|
50
|
+
- lib/yodaism.rb
|
51
|
+
- lib/yodaism/command.rb
|
52
|
+
- lib/yodaism/config.rb
|
53
|
+
- lib/yodaism/quote.rb
|
54
|
+
- lib/yodaism/quotes/quotes.txt
|
55
|
+
- lib/yodaism/version.rb
|
56
|
+
- test/helper.rb
|
57
|
+
- test/test_command.rb
|
58
|
+
- test/test_quote.rb
|
59
|
+
- yodaism.gemspec
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://www.github.com/willywos
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: yodaism
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Yodaism is about all things Yoda
|
92
|
+
test_files:
|
93
|
+
- test/test_command.rb
|
94
|
+
- test/test_quote.rb
|