Class: RBook::Onix::StreamWriter
- Inherits:
-
Object
- Object
- RBook::Onix::StreamWriter
- Defined in:
- lib/rbook/onix/stream_writer.rb
Instance Method Summary collapse
- #<<(product) ⇒ Object
- #end_document ⇒ Object
-
#initialize(output, msg) ⇒ StreamWriter
constructor
Default constructor.
- #start_document(encoding = nil) ⇒ Object
Constructor Details
#initialize(output, msg) ⇒ StreamWriter
Default constructor.
9 10 11 12 13 |
# File 'lib/rbook/onix/stream_writer.rb', line 9 def initialize(output, msg) raise ArgumentError, 'msg must be an RBook::Onix::Message object' unless msg.class == RBook::Onix::Message @output = output @msg = msg end |
Instance Method Details
#<<(product) ⇒ Object
29 30 31 |
# File 'lib/rbook/onix/stream_writer.rb', line 29 def << (product) @output.write(product.to_s) end |
#end_document ⇒ Object
33 34 35 |
# File 'lib/rbook/onix/stream_writer.rb', line 33 def end_document @output.write("</ONIXMessage>\n") end |
#start_document(encoding = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbook/onix/stream_writer.rb', line 15 def start_document(encoding = nil) decl = REXML::XMLDecl.new doctype = REXML::DocType.new('ONIXMessage', "SYSTEM \"#{RBook::Onix::Message::ONIX_DTD_URL}\"") if encoding decl.encoding = encoding else decl.encoding = "UTF-8" end @output.write(decl.to_s+"\n") @output.write(doctype.to_s+"\n") @output.write("<ONIXMessage>\n") @output.write(@msg.header.to_s) end |