Class: SimpleHelper::ResponseParser
- Inherits:
-
Object
- Object
- SimpleHelper::ResponseParser
- Defined in:
- lib/simple_helper/response_parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body, format, path) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #parse ⇒ Object
Constructor Details
#initialize(body, format, path) ⇒ ResponseParser
Returns a new instance of ResponseParser.
11 12 13 14 15 |
# File 'lib/simple_helper/response_parser.rb', line 11 def initialize(body, format, path) @body = body @format = format @path = path end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/simple_helper/response_parser.rb', line 9 def body @body end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/simple_helper/response_parser.rb', line 9 def format @format end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/simple_helper/response_parser.rb', line 9 def path @path end |
Class Method Details
.perform(body, format, path) ⇒ Object
17 18 19 |
# File 'lib/simple_helper/response_parser.rb', line 17 def self.perform(body, format, path) new(body, format, path).parse end |
Instance Method Details
#parse ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/simple_helper/response_parser.rb', line 21 def parse if body.nil? || body == 'null' || (body.valid_encoding? && body.strip.empty?) return log(message: 'Invalid response') end @body = body.gsub(/\A#{UTF8_BOM}/, '') if body.valid_encoding? && body.encoding == Encoding::UTF_8 send(format) end |