Module: Kudzu::Model::Page
- Included in:
- Adapter::Memory::Page, Agent::Response
- Defined in:
- lib/kudzu/model/page.rb
Instance Method Summary collapse
- #body ⇒ Object
- #body=(body) ⇒ Object
- #css? ⇒ Boolean
- #decoded_body ⇒ Object
- #etag ⇒ Object
- #filtered ⇒ Object
- #filtered=(filtered) ⇒ Object
- #html? ⇒ Boolean
- #js? ⇒ Boolean
- #last_modified ⇒ Object
- #parsed_doc ⇒ Object
- #status_client_error? ⇒ Boolean
- #status_gone? ⇒ Boolean
- #status_not_found? ⇒ Boolean
- #status_not_modified? ⇒ Boolean
- #status_redirection? ⇒ Boolean
- #status_server_error? ⇒ Boolean
- #status_success? ⇒ Boolean
- #text? ⇒ Boolean
- #xml? ⇒ Boolean
Instance Method Details
#body ⇒ Object
65 66 67 |
# File 'lib/kudzu/model/page.rb', line 65 def body @body end |
#body=(body) ⇒ Object
69 70 71 |
# File 'lib/kudzu/model/page.rb', line 69 def body=(body) @body = body end |
#css? ⇒ Boolean
25 26 27 |
# File 'lib/kudzu/model/page.rb', line 25 def css? !mime_type.to_s.match(%r{text/css}).nil? end |
#decoded_body ⇒ Object
81 82 83 |
# File 'lib/kudzu/model/page.rb', line 81 def decoded_body @decoded_body ||= decode_body(body) end |
#etag ⇒ Object
13 14 15 |
# File 'lib/kudzu/model/page.rb', line 13 def etag response_header['etag'] end |
#filtered ⇒ Object
73 74 75 |
# File 'lib/kudzu/model/page.rb', line 73 def filtered @filtered end |
#filtered=(filtered) ⇒ Object
77 78 79 |
# File 'lib/kudzu/model/page.rb', line 77 def filtered=(filtered) @filtered = filtered end |
#html? ⇒ Boolean
17 18 19 |
# File 'lib/kudzu/model/page.rb', line 17 def html? !mime_type.to_s.match(%r{text/html|application/xhtml\+xml}).nil? end |
#js? ⇒ Boolean
29 30 31 |
# File 'lib/kudzu/model/page.rb', line 29 def js? !mime_type.to_s.match(%r{text/javascript|application/javascript|application/x-javascript}).nil? end |
#last_modified ⇒ Object
6 7 8 9 10 11 |
# File 'lib/kudzu/model/page.rb', line 6 def last_modified last_modified = response_header['last-modified'] Time.parse(last_modified).localtime if last_modified rescue nil end |
#parsed_doc ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/kudzu/model/page.rb', line 85 def parsed_doc @parsed_doc ||= if html? Nokogiri::HTML(decoded_body) elsif xml? Nokogiri::XML(decoded_body) end end |
#status_client_error? ⇒ Boolean
45 46 47 |
# File 'lib/kudzu/model/page.rb', line 45 def status_client_error? 400 <= status && status <= 499 end |
#status_gone? ⇒ Boolean
61 62 63 |
# File 'lib/kudzu/model/page.rb', line 61 def status_gone? status == 410 end |
#status_not_found? ⇒ Boolean
57 58 59 |
# File 'lib/kudzu/model/page.rb', line 57 def status_not_found? status == 404 end |
#status_not_modified? ⇒ Boolean
53 54 55 |
# File 'lib/kudzu/model/page.rb', line 53 def status_not_modified? status == 304 end |
#status_redirection? ⇒ Boolean
41 42 43 |
# File 'lib/kudzu/model/page.rb', line 41 def status_redirection? 300 <= status && status <= 399 end |
#status_server_error? ⇒ Boolean
49 50 51 |
# File 'lib/kudzu/model/page.rb', line 49 def status_server_error? 500 <= status && status <= 599 end |
#status_success? ⇒ Boolean
37 38 39 |
# File 'lib/kudzu/model/page.rb', line 37 def status_success? 200 <= status && status <= 299 end |
#text? ⇒ Boolean
33 34 35 |
# File 'lib/kudzu/model/page.rb', line 33 def text? html? || xml? || !mime_type.to_s.match(%r{text/}).nil? end |
#xml? ⇒ Boolean
21 22 23 |
# File 'lib/kudzu/model/page.rb', line 21 def xml? !mime_type.to_s.match(%r{text/xml|application/xml|application/rss\+xml|application/atom\+xml}).nil? end |