Sha256: 849cf32bfd3fe35593faad7a6de1c97dd8c04e95c23122bb45fb8163d8d9ecc3

Contents?: true

Size: 752 Bytes

Versions: 2

Compression:

Stored size: 752 Bytes

Contents

require 'rexml/document'
require 'nokogiri'
include REXML

#  <message>
#    <to>$TO</to>
#    <body>$BODY</body>
#  </message>

module Esendex
  class Message
    attr_accessor :to, :body, :from
    
    def initialize(to, body, from=nil)
      @to = to
      @body = body
    end
    
    def xml_node
      doc = Nokogiri::XML('<message/>')
                  
      to = Nokogiri::XML::Node.new 'to', doc
      to.content = @to
      doc.root.add_child(to)
      
      body = Nokogiri::XML::Node.new 'body', doc
      body.content = @body
      doc.root.add_child(body)

      if @from
        from = Nokogiri::XML::Node.new 'from', doc
        from.content = @from
        doc.root.add_child(from)
      end
      
      doc.root
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
esendex-0.2.1 lib/esendex/message.rb
esendex-0.2.0 lib/esendex/message.rb