class Rosetta::Serializers::CSV
Public Instance Methods
call()
click to toggle source
# File lib/rosetta/serializers/csv.rb, line 9 def call ::CSV.generate do |csv| csv << headers elements.each do |element| csv << headers.map { |header| serialize_value(element[header]) } end end end
headers()
click to toggle source
# File lib/rosetta/serializers/csv.rb, line 18 def headers head, *_ = elements.map(&:properties).uniq head end
validate_input!()
click to toggle source
# File lib/rosetta/serializers/csv.rb, line 23 def validate_input! _, *others = elements.map(&:properties).uniq raise SerializationError, <<-ERROR.strip unless others.none? All objects need to share their structure to be serialized to CSV. ERROR end
Private Instance Methods
serialize_value(value)
click to toggle source
# File lib/rosetta/serializers/csv.rb, line 33 def serialize_value(value) case value when Array value.join(',') else value end end