GithubHelp home page GithubHelp logo

cc_processing's Introduction

Credit Card Processing (BT Code Challenge)

Overview of design decisions

The program's executable is housed at bin/credit_card_processing, as this is a standard pattern for Ruby libraries (putting the executable in the library's bin/ or exe/ directory).

The program logic lives within lib/credit_card_processing. I created 3 primary classes: CreditCard and Activity.

CreditCard has instance methods #charge and #credit, which are also accessible via CreditCard::Charge and CreditCard::Credit respectively. (These 2 classes are kind of like wrappers and aren't necessary strictly speaking, but I like the idea of "initializing a charge or credit object" where the card being charged or credited is provided as an argument to CreditCard::Charge.new(the_credit_card_to_charge) as I think it is more legible this way.)

The Activity class is responsible for taking an activiy string, e.g. "Add Tom 000000 $1000", and attempting to convert that activity into the appropriate domain objects.

Invoking Activity#save with an activity string of "Add Tom 000000 $1000" should attempt to store a new credit card with cardholder name of "Tom", and a credit limit of $1000.

Finally, the Runner class manages the state of the import of transaction data from the input file. It is kind of like a bridge between Activity and CreditCard. It keeps track of a little bit of its own state, e.g. the names of the cardholders who have activity in the provided inputs. This is relevant in situations where, e.g. Tom's aforementioned credit card has an invalid number, and so we do not store that card's information, but we need to report something like Tom: error in the output when running our program.

Why I chose Ruby

I am most familiar with Ruby and feel very comfortable writing "proper", test-driven, object-oriented code that is highly legible and easy to read.

How to run the code and tests

From archive file

  1. Locate the archive file cc_processing.zip (sent as email attachment to Braintree).
  2. Unarchive the source code: unzip cc_processing.zip
  3. Move into the library directory: cd cc_processing
  4. bundle install to setup dependencies
  5. To run the program: bin/credit_card_processing spec/fixtures/input.txt, or bin/credit_card_processing < spec/fixtures/input.txt.
  6. To run the tests: bin/rspec or bundle exec rspec

From source

  1. Clone this repo: git clone [email protected]:mecampbellsoup/cc_processing.git
  2. Move into the library directory: cd cc_processing
  3. bundle install to setup dependencies
  4. To run the program: bin/credit_card_processing spec/fixtures/input.txt, or bin/credit_card_processing < spec/fixtures/input.txt.
  5. To run the tests: bin/rspec or bundle exec rspec

cc_processing's People

Contributors

mecampbellsoup avatar

Watchers

 avatar  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.