ruby - What SHOULD I be seeing to know this code has done what it was supposed to? -


i doing eventmanager tutorial jumpstart labs. not .rb file read .erb file, , think may have solved that, not sure not know should seeing if running correctly , unfortunately tutorial doesn't tell you. here original question

now after simple change, no longer getting error - not getting indication code working expected. tutorial says code should creating new directory , storing copy of each 'thank you' letter file called 'output' in new directory. when run see => eventmanager initialized terminal, tells me .rb being read , (i think) .erb being read...but not see new directories/files in file structure, nor indication created - can't tell if doing anything.

i kind of expecting see kind of message telling me directory has been created, perhaps file path or something.

i have never done , i'm not sure should seeing...can tell me how know code preforming expected? , if not, why?

require "csv" require "sunlight/congress" require "erb"  sunlight::congress.api_key = "e179a6973728c4dd3fb1204283aaccb5"  def save_thank_you_letters(id, form_letter)   dir.mkdir("output") unless dir.exists? ("output")     filename = "output/thanks_#{id}.html"     file.open(filename, 'w') |file|     file.puts form_letter    end end  def legislators_by_zipcode(zipcode)   legislators = sunlight::congress::legislator.by_zipcode(zipcode) end  def clean_zipcode(zipcode)     zipcode.to_s.rjust(5,"0")[0..4] end   puts "eventmanager initialized."   contents = csv.open "event_attendees.csv", headers: true, header_converters: :symbol template_letter = file.read( "event_manager/form_letter.erb") erb_template = erb.new template_letter    contents.each |row|     id = row[0]     name = row[:first_name]     zipcode = clean_zipcode(row[:zipcode])     legislators = legislators_by_zipcode(zipcode)     form_letter = erb_template.result(binding)     save_thank_you_letters(id, form_letter)     end 

i've (ever slightly) modified save_thank_you_letters method spit out helpful information writes files:

def save_thank_you_letters(id, form_letter)   dir.mkdir("output") unless dir.exists? ("output")   filename = "output/thanks_#{id}.html"   file.open(filename, 'w') |file|     file.puts form_letter     puts "wrote id: #{id} #{filename}"   end end 

the line puts "wrote id: #{id} #{filename}" print id , file path of message has written. can place additional puts "your text here..." throughout ruby logic print more information console see fit.

side note: in general, it's super bad idea post personal api keys public forums. if key private/unique you, delete , request new one. anyone can impersonate account @ sunlight labs.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -