Class: Validate::ValidateReponse
- Inherits:
-
Object
- Object
- Validate::ValidateReponse
- Defined in:
- lib/kaba/validate.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(response, file: nil) ⇒ ValidateReponse
constructor
A new instance of ValidateReponse.
- #message ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(response, file: nil) ⇒ ValidateReponse
Returns a new instance of ValidateReponse.
58 59 60 61 62 |
# File 'lib/kaba/validate.rb', line 58 def initialize(response, file: nil) @response = response @body = JSON.parse(response.body) @file = file end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
56 57 58 |
# File 'lib/kaba/validate.rb', line 56 def body @body end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
56 57 58 |
# File 'lib/kaba/validate.rb', line 56 def file @file end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
56 57 58 |
# File 'lib/kaba/validate.rb', line 56 def response @response end |
Instance Method Details
#data ⇒ Object
72 73 74 |
# File 'lib/kaba/validate.rb', line 72 def data @body["data"] end |
#message ⇒ Object
68 69 70 |
# File 'lib/kaba/validate.rb', line 68 def @body["message"] end |
#success? ⇒ Boolean
64 65 66 |
# File 'lib/kaba/validate.rb', line 64 def success? @response.status == 200 && @body["success"] end |
#to_s ⇒ Object
76 77 78 79 80 81 |
# File 'lib/kaba/validate.rb', line 76 def to_s s = "#{'success:'.colorize(:bold_blue)} #{success? ? 'true'.colorize(:green) : 'false'.colorize(:red)}" s += "\n#{'file:'.colorize(:bold_blue)} #{file&.to_s&.colorize(:yellow)}" s += "\n#{'message:'.colorize(:bold_blue)} #{&.colorize(:yellow)}" unless success? s += "\n\n" end |