Class: Alegra::Response
- Inherits:
-
Object
- Object
- Alegra::Response
- Defined in:
- lib/alegra/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
Instance Method Summary collapse
- #call(options = {}) ⇒ Object
-
#initialize(body, formatter_class_name = 'UnderscoreFormatter') ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(body, formatter_class_name = 'UnderscoreFormatter') ⇒ Response
Returns a new instance of Response.
6 7 8 9 |
# File 'lib/alegra/response.rb', line 6 def initialize(body, formatter_class_name='UnderscoreFormatter') @body = JSON.parse(body) @formatter = Object.const_get("Alegra::Formatters::#{ formatter_class_name }").new end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/alegra/response.rb', line 4 def body @body end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
4 5 6 |
# File 'lib/alegra/response.rb', line 4 def formatter @formatter end |
Instance Method Details
#call(options = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/alegra/response.rb', line 11 def call(={}) if [:none] JSON.parse(body) else formatter.call(content: body) end end |