superacidjax / cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requirements:
=========
 - Ruby 3.0.3 is installed
 - Bundler is installed

Instructions
=================

- Unzip project
- cd /path/to/project
- Run 'bundle install'
- Run './cc_process.rb  input.txt'
- To run specs/tests, run 'bundle exec rspec'


Class descriptions
===============

At the core of the program is the 'AccountManager' class. Running  './cc_process input' reads the input file and sends each line_item to 'AccountManager'. 'AccountManager' parses each line_items and adds/credits/charges the account based on the command. Parser class is responsible for translating the line_items to arguments used to process the commands.  After creating an account, it is added to @@acounts collection, which can be accessed via 'accounts' method. 'find' method can be used to search for an account by owner name.

Account class is responsible for account information. It has four attributes:
  - owner: owner name
  - number: card number
  - limit: card limit
  - balance: Balance remaining on the card. Initialized to 0.
  - status: Set to 'invalid' if credit card number doesn't conform length/luhn10 requirement.
It has following functions:
  - credit(amt): Decreases the balance of the card associated with the provided name by the amount specified.
  - charge(amt): Increases the balance of the card associated with the provided name by the amount specified. Charges that would raise the balance over the limit are ignored as if they were declined. Charges against Luhn 10 invalid cards are ignored.
  - valid?: Checks validity of an account. Currently two types of validation is supported:
  - if the credit card number conforms to luhn10 algorithm. 'Luhn' gem is used to validate this.
  - If the credit card number exceeds 19 digits.

  Validity of an account is checked via 'Validator' class.

AccountManager is responsible for displaying the information to STDOUT. 'Formatter' class is responsible printing the accounts in required format. Accounts are listed in sorted order by their owner name. 'Sorter' class ensures that.  



Assignment Background
============

Basic Credit Card Processing
----------------------------

Imagine that you're writing software for a credit card provider.  Implement a
program that will add new credit card accounts, process charges and credits
against them, and display summary information.

## Requirements:

- Your program must accept input from two sources: a filename passed in
  command line arguments and STDIN. For example, on Linux or OSX both
  './myprogram input.txt' and './myprogram < input.txt' should work.
- Your program must accept three input commands passed with space delimited
  arguments.
- "Add" will create a new credit card for a given name, card number, and limit
   - Card numbers should be validated using Luhn 10
   - New cards start with a $0 balance
- "Charge" will increase the balance of the card associated with the provided
  name by the amount specified
   - Charges that would raise the balance over the limit are ignored as if they
     were declined
   - Charges against Luhn 10 invalid cards are ignored
- "Credit" will decrease the balance of the card associated with the provided
  name by the amount specified
   - Credits that would drop the balance below $0 will create a negative balance
   - Credits against Luhn 10 invalid cards are ignored
- When all input has been read and processed, a summary should be generated and
  written to STDOUT.
- The summary should include the name of each person followed by a colon and
  balance
- The names should be displayed alphabetically
- Display "error" instead of the balance if the credit card number does not pass
  Luhn 10

## Input Assumptions:

- All input will be valid -- there's no need to check for illegal characters
  or malformed commands.
- All input will be space delimited
- Credit card numbers may vary in length up to 19 characters
- Credit card numbers will always be numeric
- Amounts will always be prefixed with "$" and will be in whole dollars (no
  decimals)

## Example Input:

```
Add Tom 4111111111111111 $1000
Add Lisa 5454545454545454 $3000
Add Quincy 1234567890123456 $2000
Charge Tom $500
Charge Tom $800
Charge Lisa $7
Credit Lisa $100
Credit Quincy $200
```

## Example Output:

```
Lisa: $-93
Quincy: error
Tom: $500
```

About


Languages

Language:Ruby 100.0%