Class: Yodaism::Quote
- Inherits:
-
Object
- Object
- Yodaism::Quote
- Defined in:
- lib/yodaism/quote.rb
Instance Attribute Summary collapse
-
#quote_array ⇒ Object
Returns the value of attribute quote_array.
-
#word_limit ⇒ Object
Returns the value of attribute word_limit.
Instance Method Summary collapse
- #ascii ⇒ Object
-
#initialize ⇒ Quote
constructor
A new instance of Quote.
- #populate_quote_array(text_array, lines, remainder) ⇒ Object
- #put_text_in_array(word_array) ⇒ Object
- #quote_with_yoda(yoda_quote) ⇒ Object
- #random ⇒ Object
- #replace_identifiers_with_quote_text(text, yoda_quote) ⇒ Object
- #split_quote_text(text) ⇒ Object
Constructor Details
Instance Attribute Details
#quote_array ⇒ Object
Returns the value of attribute quote_array.
3 4 5 |
# File 'lib/yodaism/quote.rb', line 3 def quote_array @quote_array end |
#word_limit ⇒ Object
Returns the value of attribute word_limit.
4 5 6 |
# File 'lib/yodaism/quote.rb', line 4 def word_limit @word_limit end |
Instance Method Details
#ascii ⇒ Object
18 19 20 21 |
# File 'lib/yodaism/quote.rb', line 18 def ascii @@quote_array = Array.new quote_with_yoda(split_quote_text(random)) end |
#populate_quote_array(text_array, lines, remainder) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/yodaism/quote.rb', line 63 def populate_quote_array(text_array, lines, remainder) limit = 0 (1..lines).each do | line_num | put_text_in_array(text_array[limit, @@word_limit]) limit = @@word_limit * line_num end put_text_in_array(text_array[limit, remainder]) end |
#put_text_in_array(word_array) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/yodaism/quote.rb', line 72 def put_text_in_array(word_array) text = "" word_array.each do |word| text = text.empty? ? word : text + " " + word end @@quote_array.push(text) end |
#quote_with_yoda(yoda_quote) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yodaism/quote.rb', line 23 def quote_with_yoda(yoda_quote) yoda = %q{ .--. ::\`--._,'.::.`._.--'/:: 0 ::::. ` __::__ ' .:::: 1 ::::::-:.`'..`'.:-:::::: 2 ::::::::\ `--' /:::::::: 3 :::::::::------::::::::: 4 5 6 7 8 }.gsub(/^ {10}/,'') return replace_identifiers_with_quote_text yoda, yoda_quote end |
#random ⇒ Object
12 13 14 15 16 |
# File 'lib/yodaism/quote.rb', line 12 def random r = Random.new c = r.rand(0..@quotes.size - 1) @quotes[c].strip end |
#replace_identifiers_with_quote_text(text, yoda_quote) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yodaism/quote.rb', line 40 def replace_identifiers_with_quote_text(text, yoda_quote) #replaces the number from the template with a quote and #also replaces any left over number with a blank string # index = 0 (0..8).each do |line_num| replace_text = "" if index <= yoda_quote.size replace_text = yoda_quote[index] == nil ? "" : yoda_quote[index] end text = text.gsub(index.to_s, replace_text) index += 1 end return text end |
#split_quote_text(text) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/yodaism/quote.rb', line 56 def split_quote_text(text) text_array = text.split(" ") size = text_array.size.divmod(@@word_limit) populate_quote_array(text_array, size[0], size[1]) return @@quote_array end |