cc_manager 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/cc_manager.gemspec CHANGED
@@ -21,30 +21,54 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.post_install_message =<<EOF
23
23
 
24
- ********************************************************************************
24
+ ####################################################################################################
25
25
 
26
26
  Process credit card information with ease
27
27
  using CLI and file as input
28
28
 
29
29
  # cc_details.txt
30
- Add Tom 4111111111111111 $1000
31
- Add Lisa 5454545454545454 $3000
32
- Add Quincy 1234567890123456 $2000
33
- Charge Tom $500
34
- Charge Tom $800
35
- Charge Lisa $7
36
- Credit Lisa $100
37
- Credit Quincy $200
38
-
39
- > ccmgr cc_details.txt
30
+ Add Tom 4111111111111111 $1000
31
+ Add Lisa 5454545454545454 $3000
32
+ Add Quincy 1234567890123456 $2000
33
+ Charge Tom $500
34
+ Charge Tom $800
35
+ Charge Lisa $7
36
+ Credit Lisa $100
37
+ Credit Quincy $200
40
38
 
41
- Output:
39
+ Steps to use:
40
+
41
+ 1. Displays outputs with errors
42
+ > ccmgr -f cc_details.txt -e
43
+
44
+ OUTPUT:
45
+
46
+ Lisa: $-93
47
+ Quincy: Error
48
+ Tom: $500
49
+
50
+ ***********************************************************************************************************
51
+ Errors found in File:
52
+ +-----------------------------------+---------------------------------------------------------------------+
53
+ | Invalid Operation | Error Message |
54
+ +-----------------------------------+---------------------------------------------------------------------+
55
+ | Add Quincy 1234567890123456 $2000 | Sorry, Quincy's account cannot be added - Credit Card is invalid!!! |
56
+ | Charge Tom $800 | Sorry, Cannot Charge - Charged Amount exceeded the limit!!! |
57
+ | Credit Quincy $200 | Sorry, Cannot Add Credit - Invalid Account!!! |
58
+ +-----------------------------------+---------------------------------------------------------------------+
59
+
60
+ ***********************************************************************************************************
61
+
62
+ 2. Displays outputs without errors
63
+ > ccmgr -f cc_details.txt
64
+
65
+ OUTPUT:
42
66
 
43
- Lisa: $-93
44
- Quincy: error
45
- Tom: $500
67
+ Lisa: $-93
68
+ Quincy: Error
69
+ Tom: $500
46
70
 
47
- ********************************************************************************
71
+ ####################################################################################################
48
72
 
49
73
  EOF
50
74
 
@@ -15,7 +15,7 @@ Feature: CLI Process
15
15
  Credit Lisa $100
16
16
  """
17
17
  When I run `ccmgr -f billings_invalid.txt`
18
- Then the output should contain:
18
+ Then the output should match:
19
19
  """
20
20
  Invalid File location. Please Enter Valid path of File!!!
21
21
  """
@@ -16,21 +16,26 @@ Feature: CLI Process
16
16
  Credit Lisa $100
17
17
  Credit Quincy $200
18
18
  """
19
- When I run `ccmgr -f billings.txt`
19
+ When I run `ccmgr -f billings.txt -e`
20
20
  Then the output should match:
21
21
  """
22
- Tom: $500
22
+
23
+
24
+ OUTPUT:
25
+
23
26
  Lisa: $-93
24
27
  Quincy: Error
28
+ Tom: $500
29
+
30
+ Errors found in File:
31
+ +-----------------------------------+---------------------------------------------------------------------+
32
+ | Invalid Operation | Error Message |
33
+ +-----------------------------------+---------------------------------------------------------------------+
34
+ | Add Quincy 1234567890123456 $2000 | Sorry, Quincy's account cannot be added - Credit Card is invalid!!! |
35
+ | Charge Tom $800 | Sorry, Cannot Charge - Charged Amount exceeded the limit!!! |
36
+ | Credit Quincy $200 | Sorry, Cannot Add Credit - Invalid Account!!! |
37
+ +-----------------------------------+---------------------------------------------------------------------+
25
38
 
26
- List of Errors:
27
- +------------------+------------------------------------------------------------+
28
- | File Line Number | Error Message |
29
- +------------------+------------------------------------------------------------+
30
- | Line Number: 3 | Cannot Add Credit because Invalid Account!!! |
31
- | Line Number: 5 | Cannot Charge because Charged Amount exceeded the limit!!! |
32
- | Line Number: 8 | Cannot Add Credit because Invalid Account!!! |
33
- +------------------+------------------------------------------------------------+
34
39
  """
35
40
 
36
41
  @announce, @moderate_slow_process
@@ -43,11 +48,15 @@ Feature: CLI Process
43
48
  Charge Lisa $7
44
49
  Credit Lisa $100
45
50
  """
46
- When I run `ccmgr -f billings.txt`
51
+ When I run `ccmgr -f billings.txt -e`
47
52
  Then the output should contain:
48
53
  """
49
- Tom: $500
54
+
55
+
56
+ OUTPUT:
57
+
50
58
  Lisa: $-93
59
+ Tom: $500
51
60
  """
52
61
 
53
62
  @announce, @moderate_slow_process
@@ -60,15 +69,20 @@ Feature: CLI Process
60
69
  Charge Lisa $7
61
70
  Credit Lisa $100
62
71
  """
63
- When I run `ccmgr -f billings.txt`
64
- Then the output should contain:
72
+ When I run `ccmgr -f billings.txt -e`
73
+ Then the output should match:
65
74
  """
75
+
76
+
77
+ OUTPUT:
78
+
66
79
  Lisa: $-93
67
80
 
68
- List of Errors:
69
- +------------------+-----------------------+
70
- | File Line Number | Error Message |
71
- +------------------+-----------------------+
72
- | Line Number: 1 | Invalid Input Line!!! |
73
- +------------------+-----------------------+
81
+ Errors found in File:
82
+ +----------------------------------------+---------------------------+
83
+ | Invalid Operation | Error Message |
84
+ +----------------------------------------+---------------------------+
85
+ | Add Tom 4111111111111111 $1000 Chicago | Invalid Input Line!!! |
86
+ | Charge Tom $500 | Account not found for Tom |
87
+ +----------------------------------------+---------------------------+
74
88
  """
@@ -1,68 +1,91 @@
1
1
  module CcManager
2
2
  class Account
3
- # Contains Error message if any
4
- attr_accessor :name, :cc_number, :limit, :balance, :errors, :valid_account
3
+
4
+ # Name of the user.
5
+ attr_accessor :name
6
+
7
+ # Credit Card number of the user, only stores if the credit card number is valid against Luhn 10 algorithm.
8
+ attr_accessor :cc_number
9
+
10
+ # Charging limit set while creating new account.
11
+ attr_accessor :limit
12
+
13
+ # Balance of the user, initially its vlaue is "$0".
14
+ attr_accessor :balance
15
+
16
+ # Contains error messages if any.
17
+ attr_accessor :errors
5
18
 
19
+ # Creates new account when Add action is mentioned in the file with required arguments.
6
20
  def initialize(name, cc_number, limit)
7
21
  @errors = []
8
22
  @valid_account = false
9
23
  @name = name
10
24
  @balance = "$0"
11
- valid_amount?(limit) ? @limit = limit : @errors << "Invalid Amount specified for limit!!!"
12
- valid_card?(cc_number) ? @cc_number = cc_number : @errors << "#{name}'s account could not be added because Credit Card is invalid!!!"
13
- @valid_account = true if @errors.count == 0
25
+ valid_amount?(limit) ? @limit = limit : @errors << "Sorry, Account cannnot be Added - Invalid Amount specified for limit!!!"
26
+ valid_card?(cc_number) ? @cc_number = cc_number : @errors << "Sorry, #{name}'s account cannot be added - Credit Card is invalid!!!"
27
+ return valid?
14
28
  end
15
29
 
30
+ # Charge the user according to the given amount to charge but amount should not exceed the limit.
16
31
  def charge(charged_amount)
17
- if valid_account?
32
+ if valid?
18
33
  if valid_amount?(charged_amount)
19
34
  limit_val = get_amount_in_integer(self.limit)
20
35
  charged_amount_val = get_amount_in_integer(charged_amount)
21
36
  balance = get_amount_in_integer(self.balance)
22
- if charged_amount_val+balance < limit_val
37
+ if charged_amount_val+balance <= limit_val
23
38
  self.balance = get_amount_in_string(balance + charged_amount_val)
39
+ return true
24
40
  else
25
- @errors << "Cannot Charge because Charged Amount exceeded the limit!!!"
41
+ return "Sorry, Cannot Charge - Charged Amount exceeded the limit!!!"
26
42
  end
27
43
  else
28
- @errors << "Cannot Charge because Invalid Amount!!!"
44
+ return "Sorry, Cannot Charge - Invalid Amount!!!"
29
45
  end
30
46
  else
31
- @errors << "Cannot Charge because Invalid Account!!!"
47
+ return "Sorry, Cannot Charge - Invalid Account!!!"
32
48
  end
33
49
  end
34
50
 
51
+ # Add credit to the user according to the given amount to charge.
35
52
  def credit(credited_amount)
36
- if valid_account?
53
+ if valid?
37
54
  if valid_amount?(credited_amount)
38
55
  balance = get_amount_in_integer(self.balance)
39
56
  credited_amount_val = get_amount_in_integer(credited_amount)
40
57
  self.balance = get_amount_in_string(balance - credited_amount_val)
58
+ return true
41
59
  else
42
- @errors << "Cannot Add Credit because Invalid Amount!!!"
60
+ return "Sorry, Cannot Add Credit - Invalid Amount!!!"
43
61
  end
44
62
  else
45
- @errors << "Cannot Add Credit because Invalid Account!!!"
63
+ return "Sorry, Cannot Add Credit - Invalid Account!!!"
46
64
  end
47
65
  end
48
66
 
49
- private
50
- def valid_account?
51
- @valid_account
67
+ # Validates whether the created account is valid or not.
68
+ def valid?
69
+ @errors.empty?
52
70
  end
53
71
 
72
+ private
73
+ # Validates whether the input amount is valid or not. It must Start with a "$" sign and should not be in decimal format.
54
74
  def valid_amount?(amount)
55
75
  amount =~ /\A\$\d+\z/
56
76
  end
57
77
 
78
+ # Receives amount in string and returns into integer.
58
79
  def get_amount_in_integer(string_val)
59
80
  string_val.split("$").last.to_i
60
81
  end
61
82
 
83
+ # Receives amount in integer and returns into string.
62
84
  def get_amount_in_string(integer_val)
63
85
  "$" + integer_val.to_s
64
86
  end
65
87
 
88
+ # Validates the credit card against Luhn 10 algorithm, returns true if valid credit card and false if invalid.
66
89
  def valid_card?(number)
67
90
  digits = ''
68
91
  number.split('').reverse.each_with_index do |d,i|
@@ -1,11 +1,10 @@
1
1
  require 'fileutils'
2
2
  require 'thor'
3
3
  require 'terminal-table/import'
4
+ require File.expand_path('../../cc_manager', __FILE__)
4
5
 
5
- require File.expand_path('../../cc_manager', __FILE__) #=> requiring the gem
6
-
7
- module CcManager # :nodoc: all
8
- class CLI < Thor # :nodoc: all
6
+ module CcManager
7
+ class CLI < Thor
9
8
  include Thor::Actions
10
9
 
11
10
  default_task :process
@@ -17,83 +16,97 @@ module CcManager # :nodoc: all
17
16
  say("Version: #{CcManager::VERSION}", :green)
18
17
  end
19
18
 
20
- desc "process", "heart of this gem"
19
+ desc "process", "Reads given file and processes credit card actions as specified in the file"
21
20
  method_option :file, :required => true, :aliases => '-f', :type => :string
21
+ method_option :errors, :aliases => '-e', :type => :string
22
22
  def process
23
23
  file = options['file']
24
- accounts = []
25
- errors = []
26
- counter = 1
24
+ @accounts, @errors = [], []
27
25
  if File.exist?(file)
28
26
  File.open(file, "r") do |infile|
29
27
  while (line = infile.gets)
30
28
  args = line.split(" ")
31
- action = args.first
29
+ action = args.first.downcase
32
30
  case(action)
33
- when "Add"
34
- if args.count == 4
35
- name = args[1]
36
- card_number = args[2]
37
- limit_amount = args[3]
38
- account = CcManager::Account.new(name, card_number, limit_amount)
39
- accounts << account
40
- errors << {:line_number => counter, :message => [account.errors.first]} if account.errors.count > 0 && account.valid_account == false
41
- else
42
- errors << {:line_number => counter, :message => ["Invalid Input Line!!!"]}
43
- end
44
- when "Charge"
45
- if args.count == 3
46
- if accounts.count > 0
47
- name_to_charge = args[1]
48
- amount_to_charge = args[2]
49
- accounts.each do |account|
50
- if account.name == name_to_charge
51
- charge = account.charge(amount_to_charge)
52
- errors << {:line_number => counter, :message => charge} if charge.class == Array
53
- end
54
- end
55
- end
56
- end
57
- when "Credit"
58
- if args.count == 3
59
- if accounts.count > 0
60
- name_for_credit = args[1]
61
- amount_for_credit = args[2]
62
- accounts.each do |account|
63
- if account.name == name_for_credit
64
- credit = account.credit(amount_for_credit)
65
- errors << {:line_number => counter, :message => credit} if credit.class == Array
66
- end
67
- end
68
- end
69
- end
31
+ when "add" # Adds new account if credit card is valid and all the arguments are valid
32
+ add(args, line)
33
+ when "charge", "credit" # Updates the account
34
+ update(action, args, line)
35
+ else
36
+ @errors << {:line => line, :message => "Invalid Action Specified!!!"}
70
37
  end
71
- counter = counter + 1
72
38
  end
73
39
  end
74
40
  else
75
41
  say("Invalid File location. Please Enter Valid path of File!!!", :red)
76
42
  end
77
-
78
- accounts.each do |a|
79
- if a.cc_number.nil?
43
+
44
+ # Displaying final output
45
+ say("\n\nOUTPUT: \n\n", :yellow)
46
+ @accounts.sort! { |a,b| a.name <=> b.name }
47
+ @accounts.each do |a|
48
+ if a.valid?
49
+ say("#{a.name}: #{a.balance}", :green)
50
+ else
80
51
  say("#{a.name}: Error", :red)
52
+ end
53
+ end
54
+
55
+ if options['errors']
56
+ # Displaying Errors in tabular form
57
+ display_errors
58
+ end
59
+ end
60
+
61
+ no_tasks{
62
+ def add(args, line)
63
+ if args.count == 4
64
+ name = args[1]
65
+ card_number = args[2]
66
+ limit_amount = args[3]
67
+ if @accounts.find{|account| account.name == name}.nil?
68
+ account = CcManager::Account.new(name, card_number, limit_amount)
69
+ @accounts << account
70
+ @errors << {:line => line, :message => account.errors.last} unless account.valid?
71
+ else
72
+ @errors << {:line => line, :message => "Cannot Add - Account with #{name} Already exists!!!"}
73
+ end
81
74
  else
82
- say("#{a.name}: #{a.balance}", :green)
75
+ @errors << {:line => line, :message => "Invalid Input Line!!!"}
83
76
  end
84
77
  end
85
-
86
- if errors.count > 0
87
- say("\nList of Errors:", :yellow)
88
- require 'terminal-table'
89
- error_table = table do |t|
90
- t.headings = ["File Line Number", 'Error Message']
91
- errors.each do |error|
92
- t << ["Line Number: #{error[:line_number]}", error[:message].last]
78
+
79
+ def update(method, args, line)
80
+ if args.count == 3
81
+ if @accounts.count > 0
82
+ account_name = args[1]
83
+ amount = args[2]
84
+ if account = @accounts.find{|account| account.name == account_name}
85
+ update_state = account.send(method, amount)
86
+ @errors << {:line => line, :message => update_state} if update_state != true
87
+ else
88
+ @errors << {:line => line, :message => "Account not found for #{account_name}"}
89
+ end
93
90
  end
91
+ else
92
+ @errors << {:line => line, :message => "Invalid Input Line!!!"}
94
93
  end
95
- say(error_table, :red)
96
94
  end
97
- end
95
+
96
+ def display_errors
97
+ if @errors.count > 0
98
+ say("\n***********************************************************************************************************", :yellow)
99
+ say("Errors found in File:", :red)
100
+ error_table = table do |t|
101
+ t.headings = ["Invalid Operation", 'Error Message']
102
+ @errors.each do |error|
103
+ t << ["#{error[:line].strip}", error[:message]]
104
+ end
105
+ end
106
+ say(error_table, :red)
107
+ say("***********************************************************************************************************", :yellow)
108
+ end
109
+ end
110
+ }
98
111
  end
99
112
  end
@@ -1,3 +1,3 @@
1
1
  module CcManager
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/cc_manager.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "cc_manager/version"
2
+ require 'terminal-table'
2
3
 
3
4
  directory = File.expand_path(File.dirname(__FILE__))
4
5
 
data/spec/add_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe CcManager::Account do
9
9
  account.limit.should eql("$1000")
10
10
  account.balance.should eql("$0")
11
11
  account.errors.should be_empty
12
- account.valid_account.should be_true
12
+ account.valid?.should be_true
13
13
  end
14
14
  end
15
15
 
@@ -20,8 +20,8 @@ describe CcManager::Account do
20
20
  account.limit.should eql("$1000")
21
21
  account.cc_number.should_not eql("1234567890123456")
22
22
  account.balance.should eql("$0")
23
- account.errors.should include("Quincy's account could not be added because Credit Card is invalid!!!")
24
- account.valid_account.should_not be_true
23
+ account.errors.should include("Sorry, Quincy's account cannot be added - Credit Card is invalid!!!")
24
+ account.valid?.should_not be_true
25
25
  end
26
26
 
27
27
  it "with invalid credit card i.e. having alpha-numeric values" do
@@ -31,8 +31,8 @@ describe CcManager::Account do
31
31
  account.limit.should eql("$1000")
32
32
  account.cc_number.should_not eql("123d56h890t23456")
33
33
  account.cc_number.should be_nil
34
- account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
35
- account.valid_account.should_not be_true
34
+ account.errors.should include("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
35
+ account.valid?.should_not be_true
36
36
  end
37
37
 
38
38
  it "with invalid limit value" do
@@ -42,8 +42,8 @@ describe CcManager::Account do
42
42
  account.limit.should be_nil
43
43
  account.cc_number.should_not eql("1234567890123456")
44
44
  account.cc_number.should be_nil
45
- account.errors.should include("Invalid Amount specified for limit!!!")
46
- account.valid_account.should_not be_true
45
+ account.errors.should include("Sorry, Account cannnot be Added - Invalid Amount specified for limit!!!")
46
+ account.valid?.should_not be_true
47
47
  end
48
48
 
49
49
  it "with limit value in decimal" do
@@ -53,8 +53,8 @@ describe CcManager::Account do
53
53
  account.limit.should be_nil
54
54
  account.cc_number.should_not eql("1234567890123456")
55
55
  account.cc_number.should be_nil
56
- account.errors.should include("Invalid Amount specified for limit!!!")
57
- account.valid_account.should_not be_true
56
+ account.errors.should include("Sorry, Account cannnot be Added - Invalid Amount specified for limit!!!")
57
+ account.valid?.should_not be_true
58
58
  end
59
59
  end
60
60
  end
data/spec/charge_spec.rb CHANGED
@@ -8,8 +8,8 @@ describe CcManager::Account do
8
8
  account.cc_number.should eql("4111111111111111")
9
9
  account.limit.should eql("$1000")
10
10
  account.balance.should eql("$0")
11
- account.errors.should eql([])
12
- account.valid_account.should eql(true)
11
+ account.errors.should be_empty
12
+ account.valid?.should be_true
13
13
 
14
14
  account.charge("$500")
15
15
  account.balance.should eql("$500")
@@ -22,12 +22,12 @@ describe CcManager::Account do
22
22
  account.name.should eql("Tom")
23
23
  account.limit.should eql("$1000")
24
24
  account.balance.should eql("$0")
25
- account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
26
- account.valid_account.should eql(false)
25
+ account.errors.should include("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
26
+ account.valid?.should_not be_true
27
27
 
28
- account.charge("$500")
28
+ charge = account.charge("$500")
29
29
  account.balance.should eql("$0")
30
- account.errors.should include("Cannot Charge because Invalid Account!!!")
30
+ charge.should eql("Sorry, Cannot Charge - Invalid Account!!!")
31
31
  end
32
32
 
33
33
  it "with invalid charged amount i.e. containing decimal value" do
@@ -36,12 +36,12 @@ describe CcManager::Account do
36
36
  account.limit.should eql("$1000")
37
37
  account.balance.should eql("$0")
38
38
  account.cc_number.should eql("4111111111111111")
39
- account.errors.should eql([])
40
- account.valid_account.should eql(true)
39
+ account.errors.should be_empty
40
+ account.valid?.should be_true
41
41
 
42
- account.charge("$500.0")
42
+ charge = account.charge("$500.0")
43
43
  account.balance.should eql("$0")
44
- account.errors.should include("Cannot Charge because Invalid Amount!!!")
44
+ charge.should eql("Sorry, Cannot Charge - Invalid Amount!!!")
45
45
  end
46
46
 
47
47
  it "with invalid charged amount i.e. not starting with $ in the amount" do
@@ -50,12 +50,12 @@ describe CcManager::Account do
50
50
  account.limit.should eql("$1000")
51
51
  account.balance.should eql("$0")
52
52
  account.cc_number.should eql("4111111111111111")
53
- account.errors.should eql([])
54
- account.valid_account.should eql(true)
53
+ account.errors.should be_empty
54
+ account.valid?.should be_true
55
55
 
56
- account.charge("%500")
56
+ charge = account.charge("%500")
57
57
  account.balance.should eql("$0")
58
- account.errors.should include("Cannot Charge because Invalid Amount!!!")
58
+ charge.should eql("Sorry, Cannot Charge - Invalid Amount!!!")
59
59
  end
60
60
 
61
61
  it "with charged amount greater than the limit of Account" do
@@ -64,14 +64,15 @@ describe CcManager::Account do
64
64
  account.limit.should eql("$1000")
65
65
  account.balance.should eql("$0")
66
66
  account.cc_number.should eql("4111111111111111")
67
- account.errors.should eql([])
68
- account.valid_account.should eql(true)
67
+ account.errors.should be_empty
68
+ account.valid?.should be_true
69
69
 
70
- account.charge("$500")
70
+ charge = account.charge("$500")
71
71
  account.balance.should eql("$500")
72
- account.charge("$800")
72
+ charge_1 = account.charge("$800")
73
73
  account.balance.should eql("$500")
74
- account.errors.should include("Cannot Charge because Charged Amount exceeded the limit!!!")
74
+ charge.should be_true
75
+ charge_1.should eql("Sorry, Cannot Charge - Charged Amount exceeded the limit!!!")
75
76
  end
76
77
  end
77
78
  end
data/spec/credit_spec.rb CHANGED
@@ -8,8 +8,8 @@ describe CcManager::Account do
8
8
  account.cc_number.should eql("4111111111111111")
9
9
  account.limit.should eql("$1000")
10
10
  account.balance.should eql("$0")
11
- account.errors.should eql([])
12
- account.valid_account.should eql(true)
11
+ account.errors.should be_empty
12
+ account.valid?.should be_true
13
13
 
14
14
  account.credit("$200")
15
15
  account.balance.should eql("$-200")
@@ -21,8 +21,8 @@ describe CcManager::Account do
21
21
  account.cc_number.should eql("4111111111111111")
22
22
  account.limit.should eql("$1000")
23
23
  account.balance.should eql("$0")
24
- account.errors.should eql([])
25
- account.valid_account.should eql(true)
24
+ account.errors.should be_empty
25
+ account.valid?.should be_true
26
26
 
27
27
  account.charge("$800")
28
28
  account.balance.should eql("$800")
@@ -32,18 +32,18 @@ describe CcManager::Account do
32
32
  end
33
33
  end
34
34
 
35
- context "Adding Credit to account with Erronous conditions, " do
35
+ context "Adding Credit to account with Erroneous conditions, " do
36
36
  it "with invalid account" do
37
37
  account = CcManager::Account.new("Tom", "4111r111u1111111", "$1000")
38
38
  account.name.should eql("Tom")
39
39
  account.limit.should eql("$1000")
40
40
  account.balance.should eql("$0")
41
- account.errors.should include("Tom's account could not be added because Credit Card is invalid!!!")
42
- account.valid_account.should eql(false)
41
+ account.errors.should include("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
42
+ account.valid?.should_not be_true
43
43
 
44
- account.credit("$500")
44
+ add_credit = account.credit("$500")
45
45
  account.balance.should eql("$0")
46
- account.errors.should include("Cannot Add Credit because Invalid Account!!!")
46
+ add_credit.should eql("Sorry, Cannot Add Credit - Invalid Account!!!")
47
47
  end
48
48
 
49
49
  it "with invalid credited amount i.e. containing decimal value" do
@@ -52,12 +52,12 @@ describe CcManager::Account do
52
52
  account.limit.should eql("$1000")
53
53
  account.balance.should eql("$0")
54
54
  account.cc_number.should eql("4111111111111111")
55
- account.errors.should eql([])
56
- account.valid_account.should eql(true)
55
+ account.errors.should be_empty
56
+ account.valid?.should be_true
57
57
 
58
- account.credit("$500.0")
58
+ add_credit = account.credit("$500.0")
59
59
  account.balance.should eql("$0")
60
- account.errors.should include("Cannot Add Credit because Invalid Amount!!!")
60
+ add_credit.should eql("Sorry, Cannot Add Credit - Invalid Amount!!!")
61
61
  end
62
62
 
63
63
  it "with invalid credited amount i.e. not starting with $ in the amount" do
@@ -66,12 +66,12 @@ describe CcManager::Account do
66
66
  account.limit.should eql("$1000")
67
67
  account.balance.should eql("$0")
68
68
  account.cc_number.should eql("4111111111111111")
69
- account.errors.should eql([])
70
- account.valid_account.should eql(true)
69
+ account.errors.should be_empty
70
+ account.valid?.should be_true
71
71
 
72
- account.credit("%500")
72
+ add_credit = account.credit("%500")
73
73
  account.balance.should eql("$0")
74
- account.errors.should include("Cannot Add Credit because Invalid Amount!!!")
74
+ add_credit.should eql("Sorry, Cannot Add Credit - Invalid Amount!!!")
75
75
  end
76
76
  end
77
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cc_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &2160273460 !ruby/object:Gem::Requirement
16
+ requirement: &2154274180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.14'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2160273460
24
+ version_requirements: *2154274180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: terminal-table
27
- requirement: &2160272460 !ruby/object:Gem::Requirement
27
+ requirement: &2154273680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.4'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2160272460
35
+ version_requirements: *2154273680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aruba
38
- requirement: &2160271240 !ruby/object:Gem::Requirement
38
+ requirement: &2154273300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160271240
46
+ version_requirements: *2154273300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2160270380 !ruby/object:Gem::Requirement
49
+ requirement: &2154272680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160270380
57
+ version_requirements: *2154272680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2160269620 !ruby/object:Gem::Requirement
60
+ requirement: &2154272040 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160269620
68
+ version_requirements: *2154272040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
- requirement: &2160269040 !ruby/object:Gem::Requirement
71
+ requirement: &2154271440 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2160269040
79
+ version_requirements: *2154271440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: pry-doc
82
- requirement: &2160268260 !ruby/object:Gem::Requirement
82
+ requirement: &2154269960 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2160268260
90
+ version_requirements: *2154269960
91
91
  description: Managing Credit card processing with ease via command line app with file
92
92
  input
93
93
  email:
@@ -117,13 +117,27 @@ files:
117
117
  - bin/ccmgr
118
118
  homepage: http://manishdas.github.com/cc_manager
119
119
  licenses: []
120
- post_install_message: ! " \n ********************************************************************************\n
120
+ post_install_message: ! " \n ####################################################################################################\n
121
121
  \ \n Process credit card information with ease\n using CLI and file as input\n
122
- \ \n # cc_details.txt\n Add Tom 4111111111111111 $1000\n Add
123
- Lisa 5454545454545454 $3000\n Add Quincy 1234567890123456 $2000\n Charge
124
- Tom $500\n Charge Tom $800\n Charge Lisa $7\n Credit Lisa $100\n
125
- \ Credit Quincy $200\n\n > ccmgr cc_details.txt\n \n Output:\n\n
126
- \ Lisa: $-93\n Quincy: error\n Tom: $500\n \n ********************************************************************************\n\n"
122
+ \ \n # cc_details.txt\n Add Tom 4111111111111111 $1000\n Add
123
+ Lisa 5454545454545454 $3000\n Add Quincy 1234567890123456 $2000\n Charge
124
+ Tom $500\n Charge Tom $800\n Charge Lisa $7\n Credit
125
+ Lisa $100\n Credit Quincy $200\n \n Steps to use:\n \n 1.
126
+ Displays outputs with errors \n > ccmgr -f cc_details.txt -e\n \n
127
+ \ OUTPUT: \n\n Lisa: $-93\n Quincy: Error\n Tom:
128
+ $500\n\n ***********************************************************************************************************\n
129
+ \ Errors found in File:\n +-----------------------------------+---------------------------------------------------------------------+\n
130
+ \ | Invalid Operation | Error Message |\n
131
+ \ +-----------------------------------+---------------------------------------------------------------------+\n
132
+ \ | Add Quincy 1234567890123456 $2000 | Sorry, Quincy's account cannot be
133
+ added - Credit Card is invalid!!! |\n | Charge Tom $800 |
134
+ Sorry, Cannot Charge - Charged Amount exceeded the limit!!! |\n |
135
+ Credit Quincy $200 | Sorry, Cannot Add Credit - Invalid Account!!!
136
+ \ |\n +-----------------------------------+---------------------------------------------------------------------+\n\n
137
+ \ ***********************************************************************************************************\n
138
+ \ \n 2. Displays outputs without errors\n > ccmgr -f cc_details.txt
139
+ \n\n OUTPUT: \n\n Lisa: $-93\n Quincy: Error\n Tom:
140
+ $500\n \n ####################################################################################################\n\n"
127
141
  rdoc_options: []
128
142
  require_paths:
129
143
  - lib