module ItemsHelper
  def self.create_csv(data)
    file = Tempfile.new([Rails.root.join('tmp/').to_s, ".csv"], "")
    csv = CSV.new(file)
    data.each do |row|
      csv << row
    end

    file.rewind
    file.close
    file
  end

  def self.execute_command(command)
    buffer = []
    Open3.popen3(command) do |stdin, stdout, stderr|
      begin
        while line = stdout.readline
          buffer << line
        end
      rescue
      end
    end

    buffer
  end
end
