Class: EventReporter::Parser
- Inherits:
-
Object
- Object
- EventReporter::Parser
- Defined in:
- lib/event_reporter.rb
Instance Method Summary collapse
- #display_queue(a, b, c, d, e) ⇒ Object
- #find(input) ⇒ Object
- #find_by_city(input) ⇒ Object
- #find_by_state(input) ⇒ Object
- #find_by_zip(input) ⇒ Object
- #find_first_name(input) ⇒ Object
- #find_last_name(input) ⇒ Object
- #find_width ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #queue(input) ⇒ Object
- #queue_print(input) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 17 |
# File 'lib/event_reporter.rb', line 12 def initialize @people = [] @list = [] @queue = [] @contents = "" end |
Instance Method Details
#display_queue(a, b, c, d, e) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/event_reporter.rb', line 41 def display_queue(a,b,c,d,e) puts "\n\n\n\n\n#{"LAST NAME".ljust(a," ")}|#{"FIRST NAME".ljust(b," ")}|#{"EMAIL".ljust(c," ")}|#{"ZIPCODE".ljust(10," ")}|#{"CITY".ljust(d," ")}|#{"STATE".ljust(5," ")}|#{"ADDRESS".ljust(e," ")}|#{"PHONE".ljust(13," ")}" @queue.each_with_index do |person,i| puts "#{person[:last_name].ljust(a," ")}|#{person[:first_name].ljust(b," ")}|#{person[:email].ljust(c," ")}|#{person[:zipcode].ljust(10," ")}|#{person[:city].ljust(d," ")}|#{person[:state].upcase.ljust(5," ")}|#{person[:street].to_s.ljust(d," ")}|#{person[:phone].ljust(13," ")}" if i % 10 == 0 && i != 0 puts "Showing Matches #{i}-#{i+10} of #{@queue.length}" gets end end end |
#find(input) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/event_reporter.rb', line 120 def find(input) parts = input.split command = parts[0] case command #when 'help' then puts "\n Run 'queue count' to show number of items in queue. \n Run 'queue clear' to clear the items in the queue." when 'first_name' then find_first_name(parts[1..-1].join(" ")) #find first_name mary when 'last_name' then find_last_name(parts[1..-1].join(" ")) #find last_name smith when 'city' then find_by_city(parts[1..-1].join(" ")) when 'state' then find_by_state(parts[1..-1].join(" ")) when 'zipcode' then find_by_zip(parts[1..-1].join(" ")) else puts "What would you like to find?" end end |
#find_by_city(input) ⇒ Object
105 106 107 108 |
# File 'lib/event_reporter.rb', line 105 def find_by_city(input) @queue = @people.select{|key,value| key[:city]==input} puts "Found #{@queue.count} records" end |
#find_by_state(input) ⇒ Object
110 111 112 113 |
# File 'lib/event_reporter.rb', line 110 def find_by_state(input) @queue = @people.select{|key,value| key[:state]==input} puts "Found #{@queue.count} records" end |
#find_by_zip(input) ⇒ Object
115 116 117 118 |
# File 'lib/event_reporter.rb', line 115 def find_by_zip(input) @queue = @people.select{|key,value| key[:zipcode]==input} puts "Found #{@queue.count} records" end |
#find_first_name(input) ⇒ Object
95 96 97 98 |
# File 'lib/event_reporter.rb', line 95 def find_first_name(input) @queue = @people.select{|key,value| key[:first_name]==input} puts "Found #{@queue.count} records" end |
#find_last_name(input) ⇒ Object
100 101 102 103 |
# File 'lib/event_reporter.rb', line 100 def find_last_name(input) @queue = @people.select{|key,value| key[:last_name]==input} puts "Found #{@queue.count} records" end |
#find_width ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/event_reporter.rb', line 19 def find_width first_name_length = [12] last_name_length = [12] email_length = [] city_length = [] street_length = [] @queue.each do |person| first_name_length << person[:first_name].length last_name_length << person[:last_name].length email_length << person[:email].length city_length << person[:city].length street_length << person[:street].length end width = Hash.new(0) width[:first_name_ljust] = first_name_length.max width[:last_name_ljust] = last_name_length.max width[:email_ljust] = email_length.max width[:city_ljust] = city_length.max width[:street_ljust] = street_length.max width end |
#queue(input) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/event_reporter.rb', line 79 def queue(input) parts = input.split command = parts[0] case command when 'count' then puts "Found #{@queue.count} Records" when 'clear' puts "Queue Cleared..." @queue = [] when 'print' then queue_print(parts[-1]) when 'save' then EventReporter::SaveTo.new(parts[-1],@queue) # when 'save' then save_to(parts[-1],@queue) else puts "What would you like to queue?" end end |
#queue_print(input) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/event_reporter.rb', line 52 def queue_print(input) first_name_length = [12] last_name_length = [12] email_length = [] city_length = [] street_length = [] @queue.each do |person| first_name_length << person[:first_name].length last_name_length << person[:last_name].length email_length << person[:email].length city_length << person[:city].length street_length << person[:street].length end first_name_ljust = first_name_length.max last_name_ljust = last_name_length.max email_ljust = email_length.max city_ljust = city_length.max street_ljust = street_length.max if input == "print" display_queue(last_name_ljust , first_name_ljust , email_ljust , city_ljust , street_ljust) else @queue = @queue.sort_by{|person| person[input.to_sym]} queue_print("print") end puts "\n\n\n\n" end |
#run ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/event_reporter.rb', line 136 def run command = "" while command != "quit" printf "enter command: " input = gets.chomp.downcase parts = input.split command = parts[0] case command when 'quit' then puts "Goodbye!" when 'load' @queue = [] @people = EventReporter::LoadNewFile.new(parts[-1]) @people = @people.returner when 'find' then find(parts[1..-1].join(" ")) when 'queue' then queue(parts[1..-1].join(" ")) when 'help' a = EventReporter::HelpText.new a.show_help(parts[1..-1].join(" ")) else puts "Sorry, I don't know how to #{command}." end end end |