class Object
Public Instance Methods
build_display()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 185 def build_display result_text = "" @phrase.each do |section| # Build For a stanza with only one section if @poem[@stanza_current].length == 2 result_text = show_current_section end # Builds For a stanza with only two sections and only one phrase if @poem[@stanza_current].length == 3 # if there is only one phrase if @phrase.length == 1 #the phrase if the first phrase of the stanza if @phrase[0] == 1 result_text = "<p>#{show_current_section}</p>" + "<form id='plus_next' action='/plus_next' method='get'><button class='form-submit' type='submit'>more...</button></form>" #the phrase is the second phrase of the stanza elsif @phrase[0] == 2 result_text = "<div class='plus-minus'><form id='plus_previous' action='/plus_previous' method='get'><button class='form-submit' type='submit'>more...</button></form></div>#{show_current_section}" end end end # Builds For a stanza with only two sections and two phrases if @poem[@stanza_current].length == 3 # if there is only one phrase if @phrase.length == 2 #the phrase if the first phrase of the stanza if @phrase[0] == @section_current result_text = "<p>#{show_current_section}</p>" + "<p>#{show_next_section}</p><div class='minus-button'><form id='minus_next' action='/minus_next' method='get'><button class='form-submit' type='submit'>less...</button></form></div>" #the phrase is the second phrase of the stanza else result_text = "<div class='minus-button'><form id='minus_previous' action='/minus_previous' method='get'><button class='form-submit' type='submit'>less...</button></form></div><p>#{show_previous_section}</p><p>#{show_current_section}</p>" end end end # Builds for a Stanza with more than two sections and only one phrase if @poem[@stanza_current].length > 3 if @phrase.length == 1 if @phrase[0] == 1 result_text = "<p>#{show_current_section}</p>" + "<form id='plus_next' action='/plus_next' method='get'><button class='form-submit' type='submit'>more...</button></form>" elsif (@phrase[0] >= 2) && @phrase[0] < @poem[@stanza_current].length - 1 result_text = "<div class='plus-minus'><form id='plus_previous' action='/plus_previous' method='get'><button class='form-submit' type='submit'>more...</button></form></div>" + "<p>#{show_current_section}</p>" + "<form id='plus_next' action='/plus_next' method='get'><button class='form-submit' type='submit'>more...</button></form>" elsif @phrase[0] == @poem[@stanza_current].length - 1 result_text = "<div class='plus-minus'><form id='plus_previous' action='/plus_previous' method='get'><button class='form-submit' type='submit'>more...</button></form></div>#{show_current_section}" end end end # Builds for Stanza with more than two sections and more than one phrase if @poem[@stanza_current].length > 3 if @phrase.length > 1 # current_phrase is first in stanza and the second phrase is also displayed if @phrase[0] == 1 && @section_current == 1 && @phrase[1] == 2 result_text = "<p>#{show_current_section}</p><p>#{show_next_section}</p><div class='minus-button'><form id='minus_next' action='/minus_next' method='get'><button class='form-submit' type='submit'>less...</button></form></div>" end # current_phrase is the last phrase in the stanza and the previous phrase is also displayed if @phrase.last == @section_current && @phrase[@phrase.length - 2] == (@section_current - 1) result_text = "<div class='minus-button'><form id='minus_previous' action='/minus_previous' method='get'><button class='form-submit' type='submit'>less...</button></form></div><p>#{show_previous_section}</p><p>#{show_current_section}</p>" end # there are two phrases in array, current_phrase is not first or last stanza, # and current_phrase > second phrase if @phrase.length == 2 && @section_current != 1 && @section_current != @poem[@stanza_current].length - 1 result_text = "<div class='minus-button'><form id='minus_previous' action='/minus_previous' method='get'><button class='form-submit' type='submit'>less...</button></form></div><p>#{show_previous_section}</p><p>#{show_current_section}</p><form id='plus_next' action='/plus_next' method='get'><button class='form-submit' type='submit'>more...</button></form>" end # there are two phrases in array, current_phrase is not first or last, # and current_phrase < second phrase if @phrase.length == 2 && @section_current != 1 \ && @section_current != @poem[@stanza_current].length - 1 \ && @phrase.last > @section_current result_text = "<div class='plus-minus'><form id='plus_previous' action='/plus_previous' method='get'><button class='form-submit' type='submit'>more...</button></form></div><p>#{show_current_section}</p><p>#{show_next_section}</p><div class='minus-button'><form id='minus_next' action='/minus_next' method='get'><button class='form-submit' type='submit'>less...</button></form></div>" end # three phrases in the phrase storage array if @phrase.length == 3 result_text = "<div class='minus-button'><form id='minus_previous' action='/minus_previous' method='get'><button class='form-submit' type='submit'>less...</button></form></div><p>#{show_previous_section}</p><p>#{show_current_section}</p><p>#{show_next_section}</p><div class='minus-button'><form id='minus_next' action='/minus_next' method='get'><button class='form-submit' type='submit'>less...</button></form></div>" end end end end # show result result_text end
clear_screen()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 164 def clear_screen puts `clear` end
convert_text_to_array(text)
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 49 def convert_text_to_array(text) # text_array = text.split("\n") text.split("\n") end
create_final_poem_array(text_array)
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 55 def create_final_poem_array(text_array) # Convert text_array into a new two dimensional array (@poem) # with each stanza it's own element in the # @poem array and each segment in the @poem element an element in the @poem # element. stanza_num = 0 section = 0 text_array.each do |line| if line[0..1] == "&#" #the stanza number is after "&#" if stanza_num == 0 && @poem[0] == nil @poem[stanza_num] = [line[2..(line.length-1)]] else # "in writing stanza 2 or more" stanza_num +=1 section = 0 @poem[stanza_num] = [line[2..(line.length-1)]] end elsif line == "" #these are blank lines which tell you a new section is beginning section += 1 else temp = @poem[stanza_num][section] if temp.class == NilClass @poem[stanza_num][section] = line else @poem[stanza_num][section] = @poem[stanza_num][section] + "<br>" + line end end end end
declare_instance_variables()
click to toggle source
declare instance variables
# File lib/chapmanchri_quotemachine2.rb, line 9 def declare_instance_variables @poem = [] @stanza_pick = 0 @stanza_current = 0 @section_current = 0 @section_previous = "na" @section_next = "na" @phrase = [] end
init_poem(theFile)
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 270 def init_poem(theFile) declare_instance_variables text = read_poem(theFile) text_array = convert_text_to_array(text) create_final_poem_array(text_array) end
main_program()
click to toggle source
Main Program
# File lib/chapmanchri_quotemachine2.rb, line 175 def main_program declare_instance_variables init_poem(theFile) set_stanza_and_section set_phrase build_display # show_section # display_interface end
pick_section(stanza)
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 91 def pick_section(stanza) sections = @poem[stanza].length # section = rand(1...(sections)) rand(1...(sections)) end
pick_stanza()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 86 def pick_stanza # stanza = rand(0...(@poem.length)) rand(0...(@poem.length)) end
read_poem(file_name)
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 44 def read_poem(file_name) # text = File.read(file_name) File.read(file_name) end
set_next_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 29 def set_next_section if @section_current < (@poem[@stanza_current].length-1) @section_next = @section_current + 1 end @section_next end
set_phrase()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 25 def set_phrase @phrase[0] = @section_current end
set_previous_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 36 def set_previous_section if @section_current > 1 @section_previous = @section_current - 1 end @section_previous end
set_stanza_and_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 19 def set_stanza_and_section stanza = pick_stanza @stanza_current = stanza @section_current = pick_section(stanza) end
show_current_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 97 def show_current_section "<span class='current_section_in_text'>#{@poem[@stanza_current][@section_current]}</span>" end
show_entire_poem()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 133 def show_entire_poem print_poem = "" @poem.each_with_index do |verse, v| verse.each_with_index do |segment, s| # if s == @section_current && @stanza_current == v # print_poem = print_poem + show_current_section # # show_current_section # else # # puts segment # # puts "\n" # print_poem = print_poem + segment + "<br><br>" # end if s == 0 print_poem = print_poem + "<strong>#{segment}</strong><br>" else if @stanza_current==v && s == @section_current && s == 1 print_poem = print_poem + show_current_section elsif @stanza_current==v && s == @section_current && s != 1 print_poem = print_poem + "<br><br>" + show_current_section elsif s == 1 print_poem = print_poem + segment else print_poem = print_poem + "<br><br>" + segment end end end print_poem = print_poem + "<br><br><br>" end print_poem end
show_entire_verse()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 113 def show_entire_verse print_verse = "" @poem[@stanza_current].each_with_index do |segment, i| if i == 0 print_verse = "<strong>#{segment}</strong><br>" else if i == @section_current && i == 1 print_verse = print_verse + show_current_section elsif i == @section_current && i != 1 print_verse = print_verse + "<br><br>" + show_current_section elsif i == 1 print_verse = print_verse + segment else print_verse = print_verse + "<br><br>" + segment end end end print_verse end
show_next_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 107 def show_next_section if @section_current < (@poem[@stanza_current].length - 1) " #{@poem[@stanza_current][@section_current + 1]}" end end
show_previous_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 101 def show_previous_section if @section_current > 0 "#{@poem[@stanza_current][@section_current - 1]}" end end
show_section()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 168 def show_section @poem[@stanza_current][@section_current] end
test_method()
click to toggle source
# File lib/chapmanchri_quotemachine2.rb, line 281 def test_method "text method" end