lib/hocsv.rb
# Creates .csv file and converts data to csv
Creates .csv file and converts data to csv
Creates . csv file and converts data to csv
def to_hocsv
    filename.concat('.csv') if !filename.include?(".csv")
    headers = data.flat_map(&:keys).uniq
    CSV.open(filename, "w+b", col_sep: ', ') do |csv|
      csv <<  headers
      data.each do |hash|
        csv << hash.values_at(*headers)
      end
    end
  end
def to_hocsv filename . concat ( '.csv' ) if ! filename . include? ( ".csv" ) headers = data . flat_map ( & :keys ) . uniq CSV . open ( filename , "w+b" , col_sep : ', ' ) do | csv | csv << headers data . each do | hash | csv << hash . values_at ( * headers ) end end end
Creates .csv file and converts data to csv
Creates . csv file and converts data to csv
# adds. .csv to the end of the filename if not present #Places uniq keys into an array # Opens a new csv file in read and write mode with the provided file name or the default file name; adds column formatting # pushes headers to the file #Retrieves values at a keys location, and inserts empty space when no value is present