coda_standard 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f877398d2d3037548b41b1c90f4c12409f06c9c
4
- data.tar.gz: affb5ec7da939cdbcee9263ab276f664f5e616d0
3
+ metadata.gz: 3479770f1c2f964a28bd724563d532eafb986633
4
+ data.tar.gz: 013b22f3913eb810bacf1275d7c927b61d746104
5
5
  SHA512:
6
- metadata.gz: b220227c53fa1c9030dbea09ac0cd39f2cd4403ebce8dd4b4ef1461e6c791877eb382fd7d823a00c0608d164b03ff50abac42ac579524284647e02a6af3c01be
7
- data.tar.gz: a9d455e18abc1dae905ef75d6244f3e389e65883f0e0990aa73b5916ccd40fb09f59ff13e3306d4481a15c776d5208854f0fcf1fa646c49a640267cc1c336dec
6
+ metadata.gz: 8fb2fa665c81da93f10301db44106b50837368eed55d2cfd8005d7a0ca95c5fe3937aecdfd7d42041985ae727e9e2f276c3393d924ac1e9ffba68670d8d556c3
7
+ data.tar.gz: 43391b1375386b911bbb7effce589994404eafd64bcc35001e5a5e003b8ffb1199c675aa0e47c77b46257f8f65bfc8746deeeed0a2c65b97c06d78ce372fd053
data/README.md CHANGED
@@ -21,24 +21,32 @@ and run `bundle install` from your shell.
21
21
  ## Usage
22
22
 
23
23
  ```ruby
24
- # a new TransactionList object:
24
+
25
+ # a new TransactionList objects array:
25
26
  CodaStandard::Parser.new(filename).parse
26
27
 
27
- # or an array of transactions:
28
- CodaStandard::Parser.new(filename).parse.transactions
28
+ # or an array of Transaction Objects from the first Transaction List:
29
+ CodaStandard::Parser.new(filename).parse.first.transactions
30
+
31
+ # or maybe the BIC of the first TransactionList:
32
+ CodaStandard::Parser.new(filename).parse.first.current_bic => 'GEBABEBB'
29
33
 
30
- # or maybe the BIC:
31
- CodaStandard::Parser.new(filename).parse.current_bic => "GEBABEBB"
32
- # also available are: old_balance, current_account, current_account_type
34
+ # or the amount of the first Transaction:
35
+ CodaStandard::Parser.new(filename).parse.first.transactions[0].amount
33
36
 
34
- # or print a more readable represenation of the file
37
+ # or print a more readable representation of the file
35
38
  CodaStandard::Parser.new(filename).show
36
39
 
37
40
  # you can also find a transaction inside a transaction list object by the structured communication number
38
- CodaStandard::Parser.new(filename).parse.find_by_structured_communication('100000001234')
41
+ CodaStandard::Parser.new(filename).parse.first.find_by_structured_communication('100000001234')
39
42
  ```
43
+ The available getters for each TransactionList are: `old_balance`, `current_account`, `current_account_type`, `current_bic`
44
+
45
+ The available getters for each Transaction are: `name`, `currency`, `bic`, `address`, `postcode`, `city`, `country`, `amount`, `account`, `entry_date`, `reference_number` and `structured_communication`.
46
+
47
+ You can get the amount in cents: `amount_cents` => 50086
40
48
 
41
- The available getters for each transaction are: `name`, `currency`, `bic`, `address`, `postcode`, `city`, `country`, `amount`, `account`, `entry_date`, `reference_number` and `structured_communication`.
49
+ or with the currency: `amount_money` => '500,86 EUR'
42
50
 
43
51
  ## Contributing
44
52
 
@@ -1,10 +1,11 @@
1
1
  module CodaStandard
2
2
  class Parser
3
- attr_reader :transactions, :old_balance, :current_bic, :current_account, :current_transaction
3
+ attr_reader :transactions, :old_balance, :current_bic, :current_account, :current_transaction, :current_transaction_list
4
4
 
5
5
  def initialize(filename)
6
6
  @filename = filename
7
- @transactions = TransactionList.new
7
+ @transactions = []
8
+ @current_transaction_list = TransactionList.new
8
9
  @current_transaction = Transaction.new
9
10
  end
10
11
 
@@ -13,10 +14,11 @@ module CodaStandard
13
14
  record = Record.new(line)
14
15
  case
15
16
  when record.header?
16
- @transactions.current_bic = record.current_bic
17
+ create_transaction_list
18
+ @current_transaction_list.current_bic = record.current_bic
17
19
  when record.data_old_balance?
18
20
  set_account(record.current_account)
19
- @transactions.old_balance = record.old_balance
21
+ @current_transaction_list.old_balance = record.old_balance
20
22
  when record.data_movement1?
21
23
  create_transaction
22
24
  extract_data_movement1(record)
@@ -39,12 +41,17 @@ module CodaStandard
39
41
  end
40
42
 
41
43
  def set_account(account)
42
- @transactions.current_account = account[:account_number]
43
- @transactions.current_account_type = account[:account_type]
44
+ @current_transaction_list.current_account = account[:account_number]
45
+ @current_transaction_list.current_account_type = account[:account_type]
44
46
  end
45
47
 
46
48
  def create_transaction
47
- @current_transaction = @transactions.create
49
+ @current_transaction = @current_transaction_list.create_transaction
50
+ end
51
+
52
+ def create_transaction_list
53
+ @current_transaction_list = TransactionList.new
54
+ @transactions << @current_transaction_list
48
55
  end
49
56
 
50
57
  def extract_data_movement1(record)
@@ -66,15 +73,17 @@ module CodaStandard
66
73
 
67
74
  def show
68
75
  parse
69
- puts "**--Transactions--**\n\n"
70
- puts "Account: #{@transactions.current_account} Account type: #{@transactions.current_account_type} BIC: #{@transactions.current_bic}"
71
- puts "Old balance: #{@transactions.old_balance} \n\n"
72
76
  @transactions.each_with_index do |transaction, index|
73
- puts "-- Transaction n.#{index + 1} - number #{transaction.structured_communication} - in date #{transaction.entry_date}-- \n\n"
74
- puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC: #{transaction.bic}"
75
- puts " Amount: #{transaction.amount_money}"
76
- puts " Name: #{transaction.name}"
77
- puts " Address: #{transaction.address} #{transaction.postcode} #{transaction.city} #{transaction.country} \n\n"
77
+ puts "**--Transaction List #{ index + 1 }--**\n\n"
78
+ puts "Account: #{transaction.current_account} Account type: #{transaction.current_account_type} BIC: #{transaction.current_bic}"
79
+ puts "Old balance: #{transaction.old_balance} \n\n"
80
+ transaction.each_with_index do |transaction, index|
81
+ puts "-- Transaction n.#{index + 1} - number #{transaction.structured_communication} - in date #{transaction.entry_date}-- \n\n"
82
+ puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC: #{transaction.bic}"
83
+ puts " Amount: #{transaction.amount_money}"
84
+ puts " Name: #{transaction.name}"
85
+ puts " Address: #{transaction.address} #{transaction.postcode} #{transaction.city} #{transaction.country} \n\n"
86
+ end
78
87
  end
79
88
  end
80
89
  end
@@ -7,7 +7,7 @@ module CodaStandard
7
7
  @transactions = []
8
8
  end
9
9
 
10
- def create
10
+ def create_transaction
11
11
  @transactions << Transaction.new
12
12
  @transactions.last
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module CodaStandard
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/spec/parser_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe CodaStandard::Parser do
6
6
 
7
7
  describe "initialize" do
8
8
  it "initializes some class variables" do
9
- expect(parser.transactions).to be_a(CodaStandard::TransactionList)
9
+ expect(parser.transactions).to eq([])
10
10
  end
11
11
  end
12
12
 
@@ -15,9 +15,11 @@ describe CodaStandard::Parser do
15
15
  parser.parse
16
16
  end
17
17
 
18
- it "returns a Transactions object" do
19
- expect(parser.parse).to be_a(CodaStandard::TransactionList)
18
+ it "returns an array of TransactionLists" do
19
+ expect(parser.parse).to be_a(Array)
20
+ parser.parse.each{ |tl| expect(tl).to be_a(CodaStandard::TransactionList) }
20
21
  end
22
+
21
23
  end
22
24
 
23
25
  describe "set_address" do
@@ -45,22 +47,22 @@ describe CodaStandard::Parser do
45
47
 
46
48
  describe "set_account" do
47
49
  before :each do
48
- account = {account_number: "035918134040", account_type: "bban_be_account"}
50
+ account = { account_number: "035918134040", account_type: "bban_be_account" }
49
51
  parser.set_account(account)
50
52
  end
51
53
 
52
54
  it "sets the current_account field to the TransactionList" do
53
- expect(parser.transactions.current_account).to eq("035918134040")
55
+ expect(parser.current_transaction_list.current_account).to eq("035918134040")
54
56
  end
55
57
 
56
58
  it "sets the account_type field to the TransactionList" do
57
- expect(parser.transactions.current_account_type).to eq("bban_be_account")
59
+ expect(parser.current_transaction_list.current_account_type).to eq("bban_be_account")
58
60
  end
59
61
  end
60
62
 
61
63
  describe "show" do
62
64
  it "shows the info from the transactions" do
63
- expect{ parser.show }.to output("**--Transactions--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900.000 \n\n-- Transaction n.1 - number 100000834941 - in date 310315-- \n\n RN: 0001500000103 Account: BE53900754703405 BIC: GKCCBEBB\n Amount: 500,86 EUR\n Name: LASTNM PERSON\n Address: CHAUSSEE DE BIERE 10 1978 SOMECITY \n\n-- Transaction n.2 - number 100000835749 - in date 310315-- \n\n RN: 0001500000104 Account: LU539007547034898400 BIC: BILLLULL\n Amount: 200,00 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
65
+ expect{ parser.show }.to output("**--Transaction List 1--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900.000 \n\n-- Transaction n.1 - number 100000834941 - in date 310315-- \n\n RN: 0001500000103 Account: BE53900754703405 BIC: GKCCBEBB\n Amount: 500,86 EUR\n Name: LASTNM PERSON\n Address: CHAUSSEE DE BIERE 10 1978 SOMECITY \n\n-- Transaction n.2 - number 100000835749 - in date 310315-- \n\n RN: 0001500000104 Account: LU539007547034898400 BIC: BILLLULL\n Amount: 200,00 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
64
66
  end
65
67
  end
66
68
 
@@ -10,9 +10,9 @@ describe CodaStandard::TransactionList do
10
10
  end
11
11
 
12
12
  describe "create" do
13
- it "creates a new transaction and puts it into the array" do
14
- transaction_list.create
15
- expect(transaction_list.create).to eq transaction_list.transactions.last
13
+ it "creates a new transaction and puts it into the current transaction list" do
14
+ transaction_list.create_transaction
15
+ expect(transaction_list.create_transaction).to eq transaction_list.transactions.last
16
16
  end
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coda_standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvaro Leal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler