Skip to content

Instantly share code, notes, and snippets.

@fabiosammy
Last active January 31, 2024 15:14
Show Gist options
  • Save fabiosammy/443f3e7188a81e957e3edd3d8282c4a9 to your computer and use it in GitHub Desktop.
Save fabiosammy/443f3e7188a81e957e3edd3d8282c4a9 to your computer and use it in GitHub Desktop.
Sinatra Calculator

Sinatra Calculator

To we understand the concepts, let's create a sinatra app, that will simple calculate the inputs.

You're not limited by any structure files. Do what you learn in the last few days.

Task 1 - Make your own server code

Create the base app, adding the Gemfile (including the lock one), the rb files following the "rackup way", with a route /status that should returns a simple text "OK". Also add the rspecs for that. The server should be able to run with "bundle exec rackup". The rspec should cover the /status.

Task 2 - Add the first operations

Add the root route (/) that will receive the inputs and respond to the user. Use the ERB template render to show the calculator/input form, and the response. You can use the same path for both (form and response). Add the +(sum), -(minus) and *(multiplication) operations. Anything besides that should throw an exception/error message to the user. Rspec are mandatory.

ATTENTION! You do not need a fancy template in this task.

Task 3 - Let's divide!

Add in the calculator the divisor operator. Remember! We cannot divide by some numbers, treat it!

Extras

Only to show that you can.

Extra 1 - ERB on it

Improve the calculator adding a custom HTML. Use your creativity.

Extra 2 - Include some CSS

Make your application fancy! Besides that we're a backend class, we also gonna need to write some interface. Add a custom CSS to improve the calculator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment