Class: Philologic::Client::Document
- Defined in:
- lib/philologic-client/document.rb
Overview
Philologic document.
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Get document HTML or
nil
. -
#links ⇒ Object
readonly
Get
Array
of Philologic::Client::Link objects. -
#text ⇒ Object
readonly
Get document text or
nil
.
Attributes inherited from Response
Instance Method Summary collapse
-
#initialize(document, client = nil) ⇒ Document
constructor
Initialize Philologic::Client::Document object.
-
#links? ⇒ Boolean
Does this document contain navigation links?.
-
#text? ⇒ Boolean
Does this document contain text?.
Methods inherited from Response
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
#html ⇒ Object (readonly)
Get document HTML or nil
13 14 15 |
# File 'lib/philologic-client/document.rb', line 13 def html @html end |
#links ⇒ Object (readonly)
Get Array
of Philologic::Client::Link objects
18 19 20 |
# File 'lib/philologic-client/document.rb', line 18 def links @links end |
#text ⇒ Object (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?
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?
57 58 59 |
# File 'lib/philologic-client/document.rb', line 57 def text? @text ? true : false end |