Class: Wayfarer::Page
- Inherits:
-
Object
- Object
- Wayfarer::Page
- Defined in:
- lib/wayfarer/page.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(url:, status_code:, headers:, body:) ⇒ Page
constructor
A new instance of Page.
- #meta ⇒ Object
Constructor Details
#initialize(url:, status_code:, headers:, body:) ⇒ Page
Returns a new instance of Page.
11 12 13 14 15 16 |
# File 'lib/wayfarer/page.rb', line 11 def initialize(url:, status_code:, headers:, body:) @url = url @status_code = status_code @body = body @headers = headers.transform_keys(&:downcase) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
9 10 11 |
# File 'lib/wayfarer/page.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/wayfarer/page.rb', line 5 def headers @headers end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
5 6 7 |
# File 'lib/wayfarer/page.rb', line 5 def status_code @status_code end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/wayfarer/page.rb', line 5 def url @url end |
Instance Method Details
#doc ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wayfarer/page.rb', line 18 def doc return @doc if @doc # If no Content-Type field is present, assume HTML/XML return @doc = Wayfarer::Parsing::XML.parse_html(body) unless headers["content-type"] content_type = headers["content-type"].first sub_type = MIME::Types[content_type].first.sub_type @doc = case sub_type when "json" then Wayfarer::Parsing::JSON.parse(body) when "xml" then Wayfarer::Parsing::XML.parse_xml(body) else Wayfarer::Parsing::XML.parse_html(body) end end |
#meta ⇒ Object
34 35 36 |
# File 'lib/wayfarer/page.rb', line 34 def @meta ||= MetaInspector.new(url, document: body) end |