Skip to content

Instantly share code, notes, and snippets.

@Pcushing
Created June 20, 2012 03:36
Show Gist options
  • Save Pcushing/2957995 to your computer and use it in GitHub Desktop.
Save Pcushing/2957995 to your computer and use it in GitHub Desktop.
work in progress event_reporter.rb
require 'sunlight'
require 'csv'
class EventReporter
def run
command = ""
while command != "quit"
puts ""
printf "enter command: "
input = gets.chomp
parts = input.split
command = parts[0]
case command
when 'quit' then puts "Goodbye!"
when 'load' then load(parts[1..-1].join(" "))
when 'help' then help(parts[1..-1].join(" "))
when 'queue' then queue(parts[1..-1].join(" "))
when 'find' then
else
puts "Sorry, I don't know how to (#{command})"
end
end
end
def load(*args)
if args[0] == ""
@file = CSV.open("event_attendees.csv", {:headers => true, :header_converters => :symbol})
else
@file = CSV.open(args[0], {:headers => true, :header_converters => :symbol})
end
# @file.each do |line|
# puts line.inspect
# end
end
def help(*args)
case args[0..-1].join(" ")
when 'queue' then puts "You can all queue with 'count', 'clear', and 'print'"
when 'queue count' then puts "This'll tell you the number of records in the queue, yo."
when 'queue clear' then puts "This'll clear the queue, bird."
when 'queue print' then puts "This'll print out the queue, tab-delimited, and ish."
when 'queue print by' then puts "This'll take an argument to print the queue sorted by the argument attribute."
when 'queue save to' then puts "This'll take an argument to save the queue to a new csv."
when 'find' then puts "You can call find with an 'attribute' and 'criteria', looking for records that match."
when 'load' then puts "Load takes a 'filename' after its called"
else
puts "Here are the various commands: queue, find, load."
end
end
def queue(*args)
case args[0..-1].join(" ")
when 'count' then queue_count
else
puts "I'm not sure what you want, homie."
end
end
def queue_count
puts @file.count
end
def queue_clear
@file = nil
puts "There is no file loaded now. See here --> #{ @file }"
end
def queue_print(*args)
if args[0] == ""
@file.each do |line|
[:last_name, :first_name, :email, :zipcode, :city, :state, :street, :homephone].each do |symbol|
print "#{ line[symbol]}\t"
end
# puts "#{line[:last_name]}\t#{line[:first_name]}\t#{line[:email]}\t#{line[:zipcode]}\t#{line[:city]}\t#{line[:city]}\t#{line[:state]}\t#{line[:street]}\t#{line[:homephone]}}"
end
elsif args[0] == "by"
# Do something
else
puts "I'm not sure what you need, bro."
end
end
def queue_save_to(filename)
end
def print_file
puts @file.class
end
end
reporter = EventReporter.new
# reporter.run
reporter.load("")
# reporter.queue_print("")
# reporter.print_file
reporter.queue_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment