Sha256: ffa93c429d181ba8e8f624bd39cd83f11e4bff57a4edaaccbed3dee94ac353b5
Contents?: true
Size: 680 Bytes
Versions: 5
Compression:
Stored size: 680 Bytes
Contents
# frozen_string_literal: true require "json" require "csv" module DevSuite module Utils module Data module Serialization # Convert a hash or array of hashes to compact JSON def to_json(data) return if data.nil? ::JSON.generate(data) # Use JSON.generate for compact output end # Convert an array of hashes to CSV format def to_csv(array_of_hashes) return "" if array_of_hashes.empty? ::CSV.generate do |csv| csv << array_of_hashes.first.keys # Header row array_of_hashes.each { |hash| csv << hash.values } end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems