Class: CXML::Document
- Inherits:
-
Object
- Object
- CXML::Document
- Defined in:
- lib/cxml/document.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#payload_id ⇒ Object
Returns the value of attribute payload_id.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Document
constructor
A new instance of Document.
- #render ⇒ Object
-
#request? ⇒ Boolean
Check if document is request.
-
#response? ⇒ Boolean
Check if document is a response.
- #setup ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Document
Returns a new instance of Document.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cxml/document.rb', line 11 def initialize(data={}) if data.kind_of?(Hash) && !data.empty? @version = data['version'] @payload_id = data['payloadID'] if data['timestamp'] @timestamp = Time.parse(data['timestamp']) end if data['Header'] @header = CXML::Header.new(data['Header']) end if data['Request'] @request = CXML::Request.new(data['Request']) end if data['Response'] @response = CXML::Response.new(data['Response']) end end end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
7 8 9 |
# File 'lib/cxml/document.rb', line 7 def header @header end |
#payload_id ⇒ Object
Returns the value of attribute payload_id.
4 5 6 |
# File 'lib/cxml/document.rb', line 4 def payload_id @payload_id end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/cxml/document.rb', line 8 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
9 10 11 |
# File 'lib/cxml/document.rb', line 9 def response @response end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/cxml/document.rb', line 5 def @timestamp end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/cxml/document.rb', line 3 def version @version end |
Instance Method Details
#render ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cxml/document.rb', line 52 def render node = CXML.builder node.cXML('version' => version, 'payloadID' => payload_id, 'timestamp' => .iso8601) do |doc| doc.Header { |n| @header.render(n) } if @header @request.render(node) if @request @response.render(node) if @response end node end |
#request? ⇒ Boolean
Check if document is request
42 43 44 |
# File 'lib/cxml/document.rb', line 42 def request? !request.nil? end |
#response? ⇒ Boolean
Check if document is a response
48 49 50 |
# File 'lib/cxml/document.rb', line 48 def response? !response.nil? end |