Module: Kudzu::Model::Page

Included in:
Adapter::Memory::Page, Agent::Response
Defined in:
lib/kudzu/model/page.rb

Instance Method Summary collapse

Instance Method Details

#bodyObject


63
64
65
# File 'lib/kudzu/model/page.rb', line 63

def body
  @body
end

#body=(body) ⇒ Object


67
68
69
# File 'lib/kudzu/model/page.rb', line 67

def body=(body)
  @body = body
end

#css?Boolean

Returns:

  • (Boolean)

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

def css?
  !mime_type.to_s.match(%r{text/css}).nil?
end

#decoded_bodyObject


79
80
81
# File 'lib/kudzu/model/page.rb', line 79

def decoded_body
  @decoded_body ||= decode_body(body)
end

#etagObject


11
12
13
# File 'lib/kudzu/model/page.rb', line 11

def etag
  response_header['etag']
end

#filteredObject


71
72
73
# File 'lib/kudzu/model/page.rb', line 71

def filtered
  @filtered
end

#filtered=(filtered) ⇒ Object


75
76
77
# File 'lib/kudzu/model/page.rb', line 75

def filtered=(filtered)
  @filtered = filtered
end

#html?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'lib/kudzu/model/page.rb', line 15

def html?
  !mime_type.to_s.match(%r{text/html|application/xhtml\+xml}).nil?
end

#js?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/kudzu/model/page.rb', line 27

def js?
  !mime_type.to_s.match(%r{text/javascript|application/javascript|application/x-javascript}).nil?
end

#last_modifiedObject


4
5
6
7
8
9
# File 'lib/kudzu/model/page.rb', line 4

def last_modified
  last_modified = response_header['last-modified']
  Time.parse(last_modified).localtime if last_modified
rescue
  nil
end

#parsed_docObject


83
84
85
86
87
88
89
# File 'lib/kudzu/model/page.rb', line 83

def parsed_doc
  @parsed_doc ||= if html?
                    Nokogiri::HTML(decoded_body)
                  elsif xml?
                    Nokogiri::XML(decoded_body)
                  end
end

#status_client_error?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/kudzu/model/page.rb', line 43

def status_client_error?
  400 <= status && status <= 499
end

#status_gone?Boolean

Returns:

  • (Boolean)

59
60
61
# File 'lib/kudzu/model/page.rb', line 59

def status_gone?
  status == 410
end

#status_not_found?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'lib/kudzu/model/page.rb', line 55

def status_not_found?
  status == 404
end

#status_not_modified?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/kudzu/model/page.rb', line 51

def status_not_modified?
  status == 304
end

#status_redirection?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/kudzu/model/page.rb', line 39

def status_redirection?
  300 <= status && status <= 399
end

#status_server_error?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/kudzu/model/page.rb', line 47

def status_server_error?
  500 <= status && status <= 599
end

#status_success?Boolean

Returns:

  • (Boolean)

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

def status_success?
  200 <= status && status <= 299
end

#text?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/kudzu/model/page.rb', line 31

def text?
  html? || xml? || !mime_type.to_s.match(%r{text/}).nil?
end

#xml?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/kudzu/model/page.rb', line 19

def xml?
  !mime_type.to_s.match(%r{text/xml|application/xml|application/rss\+xml|application/atom\+xml}).nil?
end