Class: Philologic::Client::Document

Inherits:
Response
  • Object
show all
Defined in:
lib/philologic-client/document.rb

Overview

Philologic document.

Instance Attribute Summary collapse

Attributes inherited from Response

#client

Instance Method Summary collapse

Methods inherited from Response

#[], #each, #keys

Constructor Details

#initialize(document, client = nil) ⇒ Document

Initialize Philologic::Client::Document object.

Params:

document

Nokogiri document

client

(optional) Philologic::Client object or nil



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/philologic-client/document.rb', line 32

def initialize(document, client = nil)
  super

  @html = @text = nil
  unless @doc.css('div.philologic_object').first.nil?
    @text = @doc.css('div.philologic_object').children.text
    @html = @doc.css('div.philologic_object').children.to_html
  end

  @links  = []
  @doc.css('div.philologic_navigation a').each do |a|
    @links << ::Philologic::Client::Link.new( a.attributes['href'].value, a.text.strip )
  end
end

Instance Attribute Details

#htmlObject (readonly)

Get document HTML or nil



13
14
15
# File 'lib/philologic-client/document.rb', line 13

def html
  @html
end

Get Array of Philologic::Client::Link objects



18
19
20
# File 'lib/philologic-client/document.rb', line 18

def links
  @links
end

#textObject (readonly)

Get document text or nil



23
24
25
# File 'lib/philologic-client/document.rb', line 23

def text
  @text
end

Instance Method Details

#links?Boolean

Does this document contain navigation links?

Returns:

  • (Boolean)


50
51
52
# File 'lib/philologic-client/document.rb', line 50

def links?
  @links.size > 0 ? true : false
end

#text?Boolean

Does this document contain text?

Returns:

  • (Boolean)


57
58
59
# File 'lib/philologic-client/document.rb', line 57

def text?
  @text ? true : false
end