Class: WebStruct::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/webstruct/page.rb,
lib/webstruct/page/content.rb,
lib/webstruct/page/csv_header_sniffer.rb

Overview

Parsed HTTP response exposed to callers (text, optional structured data, and metadata).

Defined Under Namespace

Modules: CsvHeaderSniffer Classes: Content

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, type) ⇒ Page

Wraps a Faraday response: decodes charset when possible, classifies MIME, and parses body text.

Parameters:

  • response (Faraday::Response)
  • type (Symbol)

    coarse MIME bucket from Http::Mime.resolve



15
16
17
18
19
20
21
22
# File 'lib/webstruct/page.rb', line 15

def initialize(response, type)
  @content_type = Http::ContentType.normalize(response.headers["content-type"])
  @content = Content.new(
    response.body.to_s,
    response.headers["content-type"].to_s,
    type
  )
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/webstruct/page.rb', line 9

def content
  @content
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



9
10
11
# File 'lib/webstruct/page.rb', line 9

def content_type
  @content_type
end