Class: Proxtopus::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/proxtopus/response.rb,
lib/proxtopus/response_parser.rb

Defined Under Namespace

Modules: Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, format, elements) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/proxtopus/response.rb', line 6

def initialize(page, format, elements)
  #puts "to response"
  #raise ArgumentError, "Response.new() expects page to be of type Mechanize::Page!" if !page.is_a?(Mechanize::Page)
  #raise ArgumentError, "Response.new() expects format to be of type Symbol!" if !format.is_a?(Symbol)
  #raise ArgumentError, "Response.new() expects elements to be of type Symbol!" if !format.is_a?(Symbol)
  
  @body = page
  @format = format
  @elements = elements
  
  if format == :json
    @parsed = Parser.json(@body, @elements)
  elsif format == :xml
    @parsed = Parser.xml(@body, @elements)
  #elsif format == :rss
  #  @parsed = Parser.rss(@body, @elements)
  else
    puts "Format #{format} is currenly unsupported... consider adding it =]"
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def body
  @body
end

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def format
  @format
end

#parsedObject (readonly)

Returns the value of attribute parsed.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def parsed
  @parsed
end