This is a command-line calculator application written in Ruby. It uses the postfix notation method to perform mathematic operations in the appropriate order even when provided complex expressions involving parenthesis, addition, subtraction, multiplication, division, and exponents.
Bloculator makes use of YARD
documentation gem to dynamically build documentation based on the formatted inline comments for the code.
This ruby program also includes unit tests written with ruby's built-in MiniTest
gem. These tests facilitate maintainability, make it easier to meet goals by using test driven development, and ensure the calculator remains functional even as it is enhanced with future features (preventing new code from breaking old code).
This class encapsulates the calculator functionality.
Method | Description |
---|---|
eval | The primary function for evaluating a mathematic expression, this function takes a string as an argument and will return the result of the mathematic operations. |
to_postfix | This function converts an 'infix' ordered array to a 'postfix' ordered array to facilitate executing from left to right. |
evaluate_postfix | This function evaluates a post fix array and returns the resulting value. |
has_equal_or_higher_precedence | This function determines whether the 'left' operator has an equal or higher precedence than the 'right' (passed as arguments) and returns a boolean. |
This class provides the 'UI' (such as it is) functionality for the command-line calculator.
Method | Description |
---|---|
main_menu | This function displays the high-level options a user has (read expression history, result history, clear the view, or exit). |
calc_menu | This function displays the calculator prompt and reads the user's input. |
To use the calculator, simply run the 'main.rb' ruby file.
$> ruby './lib/main.rb'
Bloculator provides input options that allow you to clear the console as well as display all the previous mathematic expressions you've evaluated.