Class: XCAPClient::Document
- Inherits:
-
Object
- Object
- XCAPClient::Document
- Defined in:
- lib/xcapclient/document.rb
Instance Attribute Summary collapse
-
#etag ⇒ Object
The last received ETag value in a response from the server.
-
#last_response ⇒ Object
The last response received from the server.
-
#name ⇒ Object
readonly
The name of the document as it exists in the server.
-
#parsed ⇒ Object
This attribute contains the parsed instance of the XML document after calling parse method.
-
#plain ⇒ Object
Contains the plain document fetched from the server or manually set.
Instance Method Summary collapse
-
#initialize(name, plain = nil, etag = nil, parsed = nil) ⇒ Document
constructor
Create a new instance.
-
#parse ⇒ Object
Parse the plain XML document using Nokogiri and store it into @parsed attribute.
-
#reset ⇒ Object
Delete the local plain and parsed document and the ETag.
Constructor Details
#initialize(name, plain = nil, etag = nil, parsed = nil) ⇒ Document
Create a new instance. name, plain and etag are String.
21 22 23 24 25 26 27 28 29 |
# File 'lib/xcapclient/document.rb', line 21 def initialize(name, plain=nil, etag=nil, parsed=nil) @name = name @plain = plain @parsed = parsed @etag = etag # Check name. raise ConfigError, "Document `name' must be a non empty string" unless String === @name && ! @name.empty? end |
Instance Attribute Details
#etag ⇒ Object
The last received ETag value in a response from the server. It can be set manually.
12 13 14 |
# File 'lib/xcapclient/document.rb', line 12 def etag @etag end |
#last_response ⇒ Object
The last response received from the server. It’s a :Message object.
18 19 20 |
# File 'lib/xcapclient/document.rb', line 18 def last_response @last_response end |
#name ⇒ Object (readonly)
The name of the document as it exists in the server.
6 7 8 |
# File 'lib/xcapclient/document.rb', line 6 def name @name end |
#parsed ⇒ Object
This attribute contains the parsed instance of the XML document after calling parse method.
15 16 17 |
# File 'lib/xcapclient/document.rb', line 15 def parsed @parsed end |
#plain ⇒ Object
Contains the plain document fetched from the server or manually set.
9 10 11 |
# File 'lib/xcapclient/document.rb', line 9 def plain @plain end |
Instance Method Details
#parse ⇒ Object
Parse the plain XML document using Nokogiri and store it into @parsed attribute. NOTE: This method is just available if Nokogiri is installed.
41 42 43 44 45 46 47 48 |
# File 'lib/xcapclient/document.rb', line 41 def parse raise DocumentError, "Cannot parse the document as the plain document doesn't exist" begin @parsed = ::Nokogiri::XML::Document.parse(@plain, nil, "UTF-8", PARSE_OPTIONS) rescue ::Nokogiri::SyntaxError => e raise XMLParsingError, "XML parsing error: #{e.message}" end end |
#reset ⇒ Object
Delete the local plain and parsed document and the ETag.
32 33 34 35 36 |
# File 'lib/xcapclient/document.rb', line 32 def reset @plain = nil @parsed = nil @etag = nil end |