Class: XCAPClient::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/xcapclient/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, plain = nil, etag = nil, parsed = nil) ⇒ Document

Create a new instance. name, plain and etag are String.

Raises:



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

#etagObject

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_responseObject

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

#nameObject (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

#parsedObject

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

#plainObject

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

#parseObject

Parse the plain XML document using Nokogiri and store it into @parsed attribute. NOTE: This method is just available if Nokogiri is installed.

Raises:



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

#resetObject

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