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
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
23 24 25 |
# File 'lib/kudzu/model/page.rb', line 23 def css? !mime_type.to_s.match(%r{text/css}).nil? end |
#decoded_body ⇒ Object
79 80 81 |
# File 'lib/kudzu/model/page.rb', line 79 def decoded_body @decoded_body ||= decode_body(body) end |
#etag ⇒ Object
11 12 13 |
# File 'lib/kudzu/model/page.rb', line 11 def etag response_header['etag'] end |
#filtered ⇒ Object
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
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
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_modified ⇒ Object
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_doc ⇒ Object
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
43 44 45 |
# File 'lib/kudzu/model/page.rb', line 43 def status_client_error? 400 <= status && status <= 499 end |
#status_gone? ⇒ Boolean
59 60 61 |
# File 'lib/kudzu/model/page.rb', line 59 def status_gone? status == 410 end |
#status_not_found? ⇒ Boolean
55 56 57 |
# File 'lib/kudzu/model/page.rb', line 55 def status_not_found? status == 404 end |
#status_not_modified? ⇒ Boolean
51 52 53 |
# File 'lib/kudzu/model/page.rb', line 51 def status_not_modified? status == 304 end |
#status_redirection? ⇒ Boolean
39 40 41 |
# File 'lib/kudzu/model/page.rb', line 39 def status_redirection? 300 <= status && status <= 399 end |
#status_server_error? ⇒ Boolean
47 48 49 |
# File 'lib/kudzu/model/page.rb', line 47 def status_server_error? 500 <= status && status <= 599 end |
#status_success? ⇒ Boolean
35 36 37 |
# File 'lib/kudzu/model/page.rb', line 35 def status_success? 200 <= status && status <= 299 end |
#text? ⇒ 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
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 |