Class: Framecurve::Serializer
- Inherits:
-
Object
- Object
- Framecurve::Serializer
- Defined in:
- lib/framecurve/serializer.rb
Overview
Writes out a Curve object to the passed IO
Instance Method Summary collapse
-
#serialize(io, curve) ⇒ Object
Serialize the passed curve into io.
-
#validate_and_serialize(io, curve) ⇒ Object
Serialize the passed curve into io and raise an exception.
Instance Method Details
#serialize(io, curve) ⇒ Object
Serialize the passed curve into io. Will use the materialized curve version. Will write the file with CRLF linebreaks instead of LF. Also, if the passed Curve object does not contain a preamble (URL and column headers) they will be added automatically
8 9 10 11 12 13 |
# File 'lib/framecurve/serializer.rb', line 8 def serialize(io, curve) write_preamble(io) unless curve_has_preamble?(curve) curve.each do | record | io.write("%s\r\n" % record) end end |
#validate_and_serialize(io, curve) ⇒ Object
Serialize the passed curve into io and raise an exception
16 17 18 19 20 21 |
# File 'lib/framecurve/serializer.rb', line 16 def validate_and_serialize(io, curve) v = Framecurve::Validator.new v.validate(curve) raise Framecurve::Malformed, "Will not serialize a malformed curve: #{v.errors.join(', ')}" if v.any_errors? serialize(io, curve) end |