Class: Sphinxcrawl::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/sphinxcrawl/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, html) ⇒ Page

Returns a new instance of Page.



7
8
9
10
11
# File 'lib/sphinxcrawl/page.rb', line 7

def initialize(url, html)
  @url = url
  @html = html
  @field_data = {}
end

Instance Attribute Details

#html ⇒ Object (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/sphinxcrawl/page.rb', line 5

def html
  @html
end

#url ⇒ Object (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/sphinxcrawl/page.rb', line 5

def url
  @url
end

Instance Method Details

#empty? ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/sphinxcrawl/page.rb', line 13

def empty?
  !html || html.empty?
end

#eql?(compare) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


35
36
37
# File 'lib/sphinxcrawl/page.rb', line 35

def eql?(compare)
  url == compare.url
end

#field(name) ⇒ Object



23
24
25
# File 'lib/sphinxcrawl/page.rb', line 23

def field(name)
  @field_data[name] ||= get_field(name)
end

#field_names ⇒ Object



17
18
19
20
21
# File 'lib/sphinxcrawl/page.rb', line 17

def field_names
  fields.map do |n|
    n.attribute('data-field').value
  end.uniq
end

#hash ⇒ Object



40
41
42
# File 'lib/sphinxcrawl/page.rb', line 40

def hash
  url.hash
end


27
28
29
30
31
32
33
# File 'lib/sphinxcrawl/page.rb', line 27

def links
  @links ||= document.xpath('//a/@href').map(&:value).map do |url|
    # only local links (no http://)
    uri = URI.parse(url)
    uri.host.nil? && uri.scheme.nil? ? url : nil
  end.compact
end