Class: RDig::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rdig/documents.rb

Overview

Document base class

Direct Known Subclasses

FileDocument, HttpDocument

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Document

url: url of this document, may be relative to the referring doc or host. referrer: uri of the document we retrieved this link from



23
24
25
26
27
28
29
30
# File 'lib/rdig/documents.rb', line 23

def initialize(args)
  RDig.logger.debug "initialize: #{args.inspect}"
  begin
    @uri = URI.parse(args[:uri])
  rescue URI::InvalidURIError
    raise "Cannot create document using invalid URL: #{args[:uri]}"
  end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/rdig/documents.rb', line 9

def content
  @content
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



10
11
12
# File 'lib/rdig/documents.rb', line 10

def content_type
  @content_type
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/rdig/documents.rb', line 8

def uri
  @uri
end

Class Method Details

.create(url) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rdig/documents.rb', line 12

def self.create(url)
  return case url
    when /^https?:\/\//i
      HttpDocument.new(:uri => url)
    when /^file:\/\//i
      FileDocument.new(:uri => url)
  end
end

Instance Method Details

#bodyObject



33
# File 'lib/rdig/documents.rb', line 33

def body; @content[:content] end

#has_content?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rdig/documents.rb', line 40

def has_content?
  !self.content.nil?
end


34
# File 'lib/rdig/documents.rb', line 34

def links; @content[:links] end

#needs_indexing?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rdig/documents.rb', line 36

def needs_indexing?
  has_content? && (title || body)
end

#titleObject



32
# File 'lib/rdig/documents.rb', line 32

def title; @content[:title] end

#to_sObject



44
45
46
# File 'lib/rdig/documents.rb', line 44

def to_s
  "#{self.class.name}, uri=#{uri}, title=#{has_content? ? title : 'not loaded yet'}"
end