Module: Dynamised::Scraper::Writers
- Included in:
- Dynamised::Scraper
- Defined in:
- lib/dynamised/writers.rb
Instance Method Summary collapse
Instance Method Details
#write_csv(scraped_data, file_name, &spinner) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dynamised/writers.rb', line 6 def write_csv(scraped_data,file_name,&spinner) CSV.open(file_name, "wb") do |csv| headers_written = false title = "" @scraped_data.each do |url,json| hash = JSON.parse(json) # the next two lines are a temporary hack to solve the double scrape issue next unless title != hash[:title] title = hash[:title] (csv << hash.keys && headers_written = true) unless headers_written csv << hash.values spinner.call end end end |