Class: BaconIpsum::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bacon_ipsum/parser.rb

Overview

parser of results received from HTTP client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, format) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
# File 'lib/bacon_ipsum/parser.rb', line 10

def initialize(response, format)
  @response = response
  @format = format
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



8
9
10
# File 'lib/bacon_ipsum/parser.rb', line 8

def format
  @format
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/bacon_ipsum/parser.rb', line 8

def response
  @response
end

Instance Method Details

#parseObject



15
16
17
18
19
20
# File 'lib/bacon_ipsum/parser.rb', line 15

def parse
  return unless response
  return response if format != 'json'

  JSON.parse(response)
end