Giter Site home page Giter Site logo

box-creator's Introduction

Box Creator

Summary | Quickstart | Running Tests | Sample Output | Approach

Summary

A command-line application that draws a box using ASCII characters based on a given width and height.

Example output:

Quickstart

  • Ensure you have Ruby and Bundler installed and then clone the repository by running the following command:
$ git clone https://github.com/serenahathi/box-creator.git
  • Navigate to the root of the project directory and install dependencies by running the following command in the terminal:
$ bundle install
  • Open irb:
$ irb
  • Require the file:
$ require './lib/box.rb'
  • Create a new instance of the Box class and assign it to a variable. For example:
$ box = Box.new
  • Call the draw method on the variable, passing in a width and height. For example:
$ box.draw(3,3)

Running Tests

  • Tests are run using RSpec. To run the entire test suite, run the following command in the root of the project directory:
$ rspec
  • Coverage summary:

Sample Output

2.4.1 :001 > box = Box.new
 => #<Box:0x007ff52013c5a0>

2.4.1 :002 > box.draw(4,4)
┌ ╶  ╶ ┐
╷      ╷
╷      ╷
└ ╶  ╶ ┘
 => nil

2.4.1 :003 > box.draw(3,5)
┌ ╶ ┐
╷   ╷
╷   ╷
╷   ╷
└ ╶ ┘
 => nil

2.4.1 :004 > box.draw(5,8)
┌ ╶  ╶  ╶ ┐
╷         ╷
╷         ╷
╷         ╷
╷         ╷
╷         ╷
╷         ╷
└ ╶  ╶  ╶ ┘
 => nil

2.4.1 :005 > box.draw(1,1)
RuntimeError: Please enter dimensions that are greater than or equal to 2x2

Approach

  • I began by breaking down the task into smaller component parts and identified four key milestones:

    • Being able draw a 2x2 box with no user input
    • Being able to draw a box of any given width with a fixed height of 2
    • Being able to draw a box of any given width and a fixed height of 3
    • Being able to draw a box of any given width and height
  • Taking an iterative approach, I worked through each part one at a time building upon the functionality implemented in the previous step.

  • I followed the TDD cycle of writing a failing test, making it pass and then refactoring. After each test had passed, I manually tested the functionality using IRB.

  • I then focused on defending against edge cases such as the user entering a non-integer or entering box dimensions less than 2x2.

  • Once the main logic was implemented, I refactored further by:

    • Abstracting the methods used to build the box
    • Abstracting the methods used to defend against edge cases
    • Amending areas of duplication such as the creation of the horizontal edges that make up the top and bottom rows of a box to adhere to DRY principles

box-creator's People

Contributors

serenahathi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.