Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. ### A NOTE ON MY VALIDATION
  2. The condition I wrote is so long because I wanted to be able to validate the following kinds of input;
  3. * no input `""`
  4. * one digit after a decimal `"10.0"`
  5. * more than 2 numbers after a decimal `"10.00000"`
  6. * negative numbers `"-30"`
  7.  
  8. I originally wanted to have different messages for each invalid input, to personalize the user's experience, but when I starting writing an `if` statement for it...I realized how involved it would be. I thought it would have been overkill for this assignment, so I went with one generic message and compiled all of my validation code into one condition, connected with `||` and `&&` comparison operators where appropriate.
  9.  
  10. Would it have been better to create different methods for each type of validation to keep with the "one method, one responsibility convention"? I could see it going both ways...
  11.  
  12. I made a separate validation method (rb:20) for the loan duration because it required a different validating condition.
  13.  
  14.  
  15. ### A NOTE ON MY INPUT METHODS
  16. Just like my validation methods, I kept the method used to get user input for the loan duration separate because I couldn't have it being converted into a float since my `#validate_term` method would evaluate to false if were one.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement