Class: Philologic::Client::Occurrence

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

Overview

Philologic citation occurrence.

Extends Philologic::Client::Response

Usage

# <li class='philologic_occurrence'>
#   <a href="./1/0/0/0/0" class='philologic_cite'>
#     <span class='philologic_property' title='author'>William Shakespeare</span>, 
#     <i>
#       <span class='philologic_cite' title='title'>
#         The First Part of King Henry the Fourth
#       </span>
#     </i>
#     :
#     <span class='philologic_property' title='who'></span>
#   </a>
# </li>
o = Philologic::Client::Occurrence.new(html)
o['author'] # 'William Shakespeare''
o['title']  # 'The First Part of King Henry the Fourth'
o['href']   # './1/0/0/0/0'

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) ⇒ Occurrence

Initialize Philologic::Client::Occurrence object.

Params:

document

Nokogiri document

client

(optional) Philologic::Client object or nil



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/philologic-client/occurrence.rb', line 48

def initialize(document, client = nil)
  super


  # XXX @doc.css('a').each do |a|
  @doc.css('a[title=title]').each do |a|
    @properties['href'] = a.attributes['href'].children.text
    @properties['title'] = a.children.text
  end

  @doc.css('span.hit_n').each do |span|
    @properties['hit_n'] = span.children.text.to_i
  end

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

Instance Attribute Details

#htmlObject (readonly)

Get document HTML or nil



34
35
36
# File 'lib/philologic-client/occurrence.rb', line 34

def html
  @html
end

#textObject (readonly)

Get document text or nil



39
40
41
# File 'lib/philologic-client/occurrence.rb', line 39

def text
  @text
end

Instance Method Details

#text?Boolean

Does this document contain text?

Returns:

  • (Boolean)


72
73
74
# File 'lib/philologic-client/occurrence.rb', line 72

def text?
  @text ? true : false
end