Class: Rosetta::Serializers::CSV
- Inherits:
-
Base
- Object
- Base
- Rosetta::Serializers::CSV
show all
- Defined in:
- lib/rosetta/serializers/csv.rb
Instance Attribute Summary
Attributes inherited from Base
#elements
Instance Method Summary
collapse
Methods inherited from Base
call, inherited, #initialize, serialize, to_proc, #to_proc
Instance Method Details
#call ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/rosetta/serializers/csv.rb', line 9
def call
::CSV.generate do |csv|
csv <<
elements.each do |element|
csv << .map { || serialize_value(element[]) }
end
end
end
|
18
19
20
21
|
# File 'lib/rosetta/serializers/csv.rb', line 18
def
head, *_ = elements.map(&:properties).uniq
head
end
|
23
24
25
26
27
28
29
|
# 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
|