cc_manager 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ !bin
data/README.md CHANGED
@@ -1,3 +1,86 @@
1
- # Credit Card Manager
1
+ # Credit Card Manager Gem
2
+ Managing Credit card processing with ease via command line.
2
3
 
3
- Managing Credit card processing with ease via command line app with file input.
4
+ ##Installation
5
+
6
+ gem install cc_manager
7
+
8
+ ##Usage
9
+
10
+ ###Step 1: Make a file in and write the operations for the processing
11
+
12
+ for example, I created a file "cc_file.txt" on desktop of my system
13
+
14
+ #cc_file.txt
15
+ Add Tom 4111111111111111 $1000
16
+ Add Lisa 5454545454545454 $3000
17
+ Add Quincy 1234567890123456 $2000
18
+ Charge Tom $500
19
+ Charge Tom $800
20
+ Charge Lisa $7
21
+ Credit Lisa $100
22
+ Credit Quincy $200
23
+
24
+ ###Step 2: Run following command in CLI to see the final output according to the operations written in file
25
+
26
+ Case 1: If you want final output without any error messages
27
+
28
+ ccmgr --file=/Users/manish/Desktop/cc_file.txt
29
+ --file takes the path of the file for processing
30
+
31
+ Case 2: If you want final output displaying error messages if any
32
+
33
+ ccmgr --file=/Users/manish/Desktop/cc_file.txt --errors
34
+ OR
35
+
36
+ ccmgr -f=/Users/manish/Desktop/cc_file.txt -e
37
+ aliases:
38
+
39
+ --file = -f
40
+ --errors = -e
41
+
42
+ ##Demo Output
43
+
44
+ ccmgr --file=/Users/manish/Desktop/cc_file.txt
45
+
46
+ Output displayed in the Terminal will be:
47
+
48
+ OUTPUT:
49
+
50
+ Lisa: $-93
51
+ Quincy: Error
52
+ Tom: $500
53
+
54
+ If you want output with error messages, then type:
55
+
56
+ ccmgr --file=/Users/manish/Desktop/cc_file.txt --errors
57
+
58
+ output displayed in the Terminal will be followed by the error messages in the format as shown below:
59
+
60
+ *************************************************************************************************************************
61
+ 3 Errors found in File:
62
+ +---------------------------------------------+--------------------------------------------------------------+
63
+ | Invalid Operation | Error Message |
64
+ +---------------------------------------------+--------------------------------------------------------------+
65
+ | Add Quincy 1234567890123456 $2000 (line: 3) | Quincy's account cannot be added - Credit Card is invalid!!! |
66
+ | Charge Tom $800 (line: 5) | Cannot Charge - Charged Amount exceeded the limit!!! |
67
+ | Credit Quincy $200 (line: 8) | Cannot Add Credit - Invalid Account!!! |
68
+ +---------------------------------------------+--------------------------------------------------------------+
69
+
70
+ ##Version of gem
71
+
72
+ To get the version:
73
+
74
+ ccmgr version
75
+ OR
76
+
77
+ ccmgr -v
78
+
79
+ ##Help
80
+ For Help
81
+
82
+ ccmgr help
83
+
84
+ Further Help
85
+
86
+ ccmgr help process
@@ -27,14 +27,15 @@ Feature: CLI Process
27
27
  Quincy: Error
28
28
  Tom: $500
29
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
- +-----------------------------------+---------------------------------------------------------------------+
30
+
31
+ 3 Errors found in File:
32
+ +---------------------------------------------+--------------------------------------------------------------+
33
+ | Invalid Operation(Line) | Error Message |
34
+ +---------------------------------------------+--------------------------------------------------------------+
35
+ | Add Quincy 1234567890123456 $2000 (line: 3) | Quincy's account cannot be added - Credit Card is invalid!!! |
36
+ | Charge Tom $800 (line: 5) | Cannot Charge - Charged Amount exceeded the limit!!! |
37
+ | Credit Quincy $200 (line: 8) | Cannot Add Credit - Invalid Account!!! |
38
+ +---------------------------------------------+--------------------------------------------------------------+
38
39
 
39
40
  """
40
41
 
@@ -78,11 +79,12 @@ Feature: CLI Process
78
79
 
79
80
  Lisa: $-93
80
81
 
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
- +----------------------------------------+---------------------------+
82
+
83
+ 2 Errors found in File:
84
+ +--------------------------------------------------+--------------------------+
85
+ | Invalid Operation(Line) | Error Message |
86
+ +--------------------------------------------------+--------------------------+
87
+ | Add Tom 4111111111111111 $1000 Chicago (line: 1) | Invalid Input Line!!! |
88
+ | Charge Tom $500 (line: 3) | No Account found for Tom |
89
+ +--------------------------------------------------+--------------------------+
88
90
  """
@@ -22,8 +22,8 @@ module CcManager
22
22
  @valid_account = false
23
23
  @name = name
24
24
  @balance = "$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!!!"
25
+ valid_amount?(limit) ? @limit = limit : @errors << "Account cannnot be Added - Invalid Amount specified for limit!!!"
26
+ valid_card?(cc_number) ? @cc_number = cc_number : @errors << "#{name}'s account cannot be added - Credit Card is invalid!!!"
27
27
  return valid?
28
28
  end
29
29
 
@@ -38,13 +38,13 @@ module CcManager
38
38
  self.balance = get_amount_in_string(balance + charged_amount_val)
39
39
  return true
40
40
  else
41
- return "Sorry, Cannot Charge - Charged Amount exceeded the limit!!!"
41
+ return "Cannot Charge - Charged Amount exceeded the limit!!!"
42
42
  end
43
43
  else
44
- return "Sorry, Cannot Charge - Invalid Amount!!!"
44
+ return "Cannot Charge - Invalid Amount!!!"
45
45
  end
46
46
  else
47
- return "Sorry, Cannot Charge - Invalid Account!!!"
47
+ return "Cannot Charge - Invalid Account!!!"
48
48
  end
49
49
  end
50
50
 
@@ -57,10 +57,10 @@ module CcManager
57
57
  self.balance = get_amount_in_string(balance - credited_amount_val)
58
58
  return true
59
59
  else
60
- return "Sorry, Cannot Add Credit - Invalid Amount!!!"
60
+ return "Cannot Add Credit - Invalid Amount!!!"
61
61
  end
62
62
  else
63
- return "Sorry, Cannot Add Credit - Invalid Account!!!"
63
+ return "Cannot Add Credit - Invalid Account!!!"
64
64
  end
65
65
  end
66
66
 
@@ -11,17 +11,18 @@ module CcManager
11
11
 
12
12
  map "-v" => :version
13
13
 
14
- desc "version", "Shows the current version of cloudfactory gem"
14
+ desc "version", "Shows the current version of cc_manager gem"
15
15
  def version
16
16
  say("Version: #{CcManager::VERSION}", :green)
17
17
  end
18
18
 
19
19
  desc "process", "Reads given file and processes credit card actions as specified in the file"
20
- method_option :file, :required => true, :aliases => '-f', :type => :string
21
- method_option :errors, :aliases => '-e', :type => :string
20
+ method_option :file, :required => true, :aliases => '-f', :type => :string, :desc => "Takes the path of the file for the processing"
21
+ method_option :errors, :aliases => '-e', :type => :string, :desc => "Displays output with the errors encountered. Type `ccmgr --file=file_path --errors` in Terminal"
22
22
  def process
23
23
  file = options['file']
24
24
  @accounts, @errors = [], []
25
+ counter = 1
25
26
  if File.exist?(file)
26
27
  File.open(file, "r") do |infile|
27
28
  while (line = infile.gets)
@@ -29,12 +30,13 @@ module CcManager
29
30
  action = args.first.downcase
30
31
  case(action)
31
32
  when "add" # Adds new account if credit card is valid and all the arguments are valid
32
- add(args, line)
33
+ add(args, line, counter)
33
34
  when "charge", "credit" # Updates the account
34
- update(action, args, line)
35
+ update(action, args, line, counter)
35
36
  else
36
- @errors << {:line => line, :message => "Invalid Action Specified!!!"}
37
+ add_errors(counter, line, "Invalid Action Specified!!!")
37
38
  end
39
+ counter = counter + 1
38
40
  end
39
41
  end
40
42
  else
@@ -59,54 +61,63 @@ module CcManager
59
61
  end
60
62
 
61
63
  no_tasks{
62
- def add(args, line)
64
+ def add(args, line, counter)
63
65
  if args.count == 4
64
66
  name = args[1]
65
67
  card_number = args[2]
66
68
  limit_amount = args[3]
67
69
  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?
70
+ if @accounts.find{|account| account.cc_number == card_number}.nil?
71
+ account = CcManager::Account.new(name, card_number, limit_amount)
72
+ @accounts << account
73
+ add_errors(counter, line, account.errors.last) unless account.valid?
74
+ else
75
+ add_errors(counter, line, "Cannot Add - Card number already in use!!!")
76
+ end
71
77
  else
72
- @errors << {:line => line, :message => "Cannot Add - Account with #{name} Already exists!!!"}
78
+ add_errors(counter, line, "Cannot Add - Account with #{name} Already exists!!!")
73
79
  end
74
80
  else
75
- @errors << {:line => line, :message => "Invalid Input Line!!!"}
81
+ add_errors(counter, line, "Invalid Input Line!!!")
76
82
  end
77
83
  end
78
84
 
79
- def update(method, args, line)
85
+ def update(method, args, line, counter)
80
86
  if args.count == 3
81
87
  if @accounts.count > 0
82
88
  account_name = args[1]
83
89
  amount = args[2]
84
90
  if account = @accounts.find{|account| account.name == account_name}
85
91
  update_state = account.send(method, amount)
86
- @errors << {:line => line, :message => update_state} if update_state != true
92
+ add_errors(counter, line, update_state) if update_state != true
87
93
  else
88
- @errors << {:line => line, :message => "Account not found for #{account_name}"}
94
+ add_errors(counter, line, "No Account found for #{account_name}!!!")
89
95
  end
96
+ else
97
+ add_errors(counter, line, "No Account found for #{args[1]} to #{method}!!!")
90
98
  end
91
99
  else
92
- @errors << {:line => line, :message => "Invalid Input Line!!!"}
100
+ add_errors(counter, line, "Invalid Input Line!!!")
93
101
  end
94
102
  end
95
103
 
96
104
  def display_errors
97
105
  if @errors.count > 0
98
- say("\n***********************************************************************************************************", :yellow)
99
- say("Errors found in File:", :red)
106
+ say("\n*************************************************************************************************************************", :yellow)
107
+ say("#{@errors.count} Errors found in File:", :red)
100
108
  error_table = table do |t|
101
109
  t.headings = ["Invalid Operation", 'Error Message']
102
110
  @errors.each do |error|
103
- t << ["#{error[:line].strip}", error[:message]]
111
+ t << ["#{error[:line].strip} (line: #{error[:line_number]})", error[:message]]
104
112
  end
105
113
  end
106
114
  say(error_table, :red)
107
- say("***********************************************************************************************************", :yellow)
108
115
  end
109
116
  end
117
+
118
+ def add_errors(counter, line, message)
119
+ @errors << {:line_number => counter, :line => line, :message => message}
120
+ end
110
121
  }
111
122
  end
112
123
  end
@@ -1,3 +1,3 @@
1
1
  module CcManager
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/add_spec.rb CHANGED
@@ -20,7 +20,7 @@ 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("Sorry, Quincy's account cannot be added - Credit Card is invalid!!!")
23
+ account.errors.should include("Quincy's account cannot be added - Credit Card is invalid!!!")
24
24
  account.valid?.should_not be_true
25
25
  end
26
26
 
@@ -31,7 +31,7 @@ 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("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
34
+ account.errors.should include("Tom's account cannot be added - Credit Card is invalid!!!")
35
35
  account.valid?.should_not be_true
36
36
  end
37
37
 
@@ -42,7 +42,7 @@ 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("Sorry, Account cannnot be Added - Invalid Amount specified for limit!!!")
45
+ account.errors.should include("Account cannnot be Added - Invalid Amount specified for limit!!!")
46
46
  account.valid?.should_not be_true
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ 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("Sorry, Account cannnot be Added - Invalid Amount specified for limit!!!")
56
+ account.errors.should include("Account cannnot be Added - Invalid Amount specified for limit!!!")
57
57
  account.valid?.should_not be_true
58
58
  end
59
59
  end
data/spec/charge_spec.rb CHANGED
@@ -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("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
25
+ account.errors.should include("Tom's account cannot be added - Credit Card is invalid!!!")
26
26
  account.valid?.should_not be_true
27
27
 
28
28
  charge = account.charge("$500")
29
29
  account.balance.should eql("$0")
30
- charge.should eql("Sorry, Cannot Charge - Invalid Account!!!")
30
+ charge.should eql("Cannot Charge - Invalid Account!!!")
31
31
  end
32
32
 
33
33
  it "with invalid charged amount i.e. containing decimal value" do
@@ -41,7 +41,7 @@ describe CcManager::Account do
41
41
 
42
42
  charge = account.charge("$500.0")
43
43
  account.balance.should eql("$0")
44
- charge.should eql("Sorry, Cannot Charge - Invalid Amount!!!")
44
+ charge.should eql("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
@@ -55,7 +55,7 @@ describe CcManager::Account do
55
55
 
56
56
  charge = account.charge("%500")
57
57
  account.balance.should eql("$0")
58
- charge.should eql("Sorry, Cannot Charge - Invalid Amount!!!")
58
+ charge.should eql("Cannot Charge - Invalid Amount!!!")
59
59
  end
60
60
 
61
61
  it "with charged amount greater than the limit of Account" do
@@ -72,7 +72,7 @@ describe CcManager::Account do
72
72
  charge_1 = account.charge("$800")
73
73
  account.balance.should eql("$500")
74
74
  charge.should be_true
75
- charge_1.should eql("Sorry, Cannot Charge - Charged Amount exceeded the limit!!!")
75
+ charge_1.should eql("Cannot Charge - Charged Amount exceeded the limit!!!")
76
76
  end
77
77
  end
78
78
  end
data/spec/credit_spec.rb CHANGED
@@ -38,12 +38,12 @@ describe CcManager::Account do
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("Sorry, Tom's account cannot be added - Credit Card is invalid!!!")
41
+ account.errors.should include("Tom's account cannot be added - Credit Card is invalid!!!")
42
42
  account.valid?.should_not be_true
43
43
 
44
44
  add_credit = account.credit("$500")
45
45
  account.balance.should eql("$0")
46
- add_credit.should eql("Sorry, Cannot Add Credit - Invalid Account!!!")
46
+ add_credit.should eql("Cannot Add Credit - Invalid Account!!!")
47
47
  end
48
48
 
49
49
  it "with invalid credited amount i.e. containing decimal value" do
@@ -57,7 +57,7 @@ describe CcManager::Account do
57
57
 
58
58
  add_credit = account.credit("$500.0")
59
59
  account.balance.should eql("$0")
60
- add_credit.should eql("Sorry, Cannot Add Credit - Invalid Amount!!!")
60
+ add_credit.should eql("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
@@ -71,7 +71,7 @@ describe CcManager::Account do
71
71
 
72
72
  add_credit = account.credit("%500")
73
73
  account.balance.should eql("$0")
74
- add_credit.should eql("Sorry, Cannot Add Credit - Invalid Amount!!!")
74
+ add_credit.should eql("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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-05 00:00:00.000000000Z
12
+ date: 2011-09-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &2154274180 !ruby/object:Gem::Requirement
16
+ requirement: &2154276740 !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: *2154274180
24
+ version_requirements: *2154276740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: terminal-table
27
- requirement: &2154273680 !ruby/object:Gem::Requirement
27
+ requirement: &2154262360 !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: *2154273680
35
+ version_requirements: *2154262360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aruba
38
- requirement: &2154273300 !ruby/object:Gem::Requirement
38
+ requirement: &2154260660 !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: *2154273300
46
+ version_requirements: *2154260660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2154272680 !ruby/object:Gem::Requirement
49
+ requirement: &2154259820 !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: *2154272680
57
+ version_requirements: *2154259820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2154272040 !ruby/object:Gem::Requirement
60
+ requirement: &2154258840 !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: *2154272040
68
+ version_requirements: *2154258840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
- requirement: &2154271440 !ruby/object:Gem::Requirement
71
+ requirement: &2154258240 !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: *2154271440
79
+ version_requirements: *2154258240
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: pry-doc
82
- requirement: &2154269960 !ruby/object:Gem::Requirement
82
+ requirement: &2154257400 !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: *2154269960
90
+ version_requirements: *2154257400
91
91
  description: Managing Credit card processing with ease via command line app with file
92
92
  input
93
93
  email:
@@ -102,6 +102,7 @@ files:
102
102
  - Gemfile
103
103
  - README.md
104
104
  - Rakefile
105
+ - bin/ccmgr
105
106
  - cc_manager.gemspec
106
107
  - features/invalid_file.feature
107
108
  - features/process.feature
@@ -114,7 +115,6 @@ files:
114
115
  - spec/charge_spec.rb
115
116
  - spec/credit_spec.rb
116
117
  - spec/spec_helper.rb
117
- - bin/ccmgr
118
118
  homepage: http://manishdas.github.com/cc_manager
119
119
  licenses: []
120
120
  post_install_message: ! " \n ####################################################################################################\n