multicash 0.0.2 → 0.0.3

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: 109e38aa0bce3a07aae3beae23b1e0d5bb5cee00
4
- data.tar.gz: b13ee8cd30ee798c4db0f3053aecd6dc4f509ba8
3
+ metadata.gz: 82a2eb079904b7f749e89c682740f34d9cd9794c
4
+ data.tar.gz: 3847c1756f0745763e8ffbdabdb4277f699e366d
5
5
  SHA512:
6
- metadata.gz: e19e707697946023ce8bcf7bfcf64c09ad3a5f0d3a859d4b4e6aee21936587de20160899efeaac7ffbcc1a522cf96575d94d197fac59db7eeb246be55dc7d409
7
- data.tar.gz: 930e185f3707633320a4e0e417dc53daf538226f318e9bbe826d9868f4d4e059ff5e02498662315869ac6e3bac1c012f0ebb1ac56bc79eb0866bab42be0092ca
6
+ metadata.gz: ffcc2887d1a901eedafd445e45fd07583aecf4ec008218624f2b7a1c53cb9fbfd498f624512dd64bba668577d6260afd6068cce98e9ea3e88a848a6b33e61169
7
+ data.tar.gz: 305177c4f9fb018f68ff8f0d4fb5ca1dad68f605c6d4344c0a7fd33ad063f1937610a0183f78867b07d1651e81247626124b097e249245a59cb46774de320daa
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -4,7 +4,7 @@ module Multicash
4
4
  include ActiveModel::Validations
5
5
 
6
6
  CURRENCIES = %w{AUD BGN CAD CHF DKK EUR GBP JPY NOK RUR SEK TRL USD}
7
- CURRENCY_FORMAT = /\A\d{1,11}.\d{2}\z/
7
+ CURRENCY_FORMAT = /\A\d{1,11}.\d{1,2}\z/
8
8
 
9
9
  attr_accessor :value, :currency
10
10
  attr_reader :errors
@@ -13,7 +13,7 @@ module Multicash
13
13
  end
14
14
 
15
15
  def generate
16
- return self.errors.full_messages unless self.valid
16
+ return self.errors.full_messages.to_sentence unless self.valid?
17
17
 
18
18
  "#{self.header}#{self.body}"
19
19
  end
@@ -1,12 +1,15 @@
1
1
  module Multicash
2
2
  class PaymentOrder
3
- attr_accessor :reference, :transfers_number
4
- attr_reader :transfers, :total_ammount, :currency, :ordering_bae, :date, :errors
3
+ extend ActiveModel::Naming
4
+ include ActiveModel::Validations
5
+
6
+ attr_accessor :reference, :transfers_number, :errors
7
+ attr_reader :transfers, :total_ammount, :currency, :ordering_bae, :date
5
8
 
6
9
  def initialize
7
10
  @currency = nil
8
11
  @date = Time.now.strftime('%y%m%d')
9
- @errors = []
12
+ @errors = ActiveModel::Errors.new(self)
10
13
  @ordering_bae = nil
11
14
  @transfers = []
12
15
  @total_ammount = 0.00
@@ -15,11 +18,12 @@ module Multicash
15
18
  def << (transfer)
16
19
  if transfer.valid?
17
20
  @transfers << transfer
21
+ transfer.reference_counter = @transfers.size
18
22
  @total_ammount += (transfer.ammount.to_f)
19
23
  @currency ||= transfer.currency
20
24
  @ordering_bae ||= transfer.ordering_bae
21
25
  else
22
- errors.add(:transfer, transfer.errors.full_messages)
26
+ errors.add("#{transfer.reference_counter}", transfer.errors.full_messages)
23
27
  end
24
28
  end
25
29
 
@@ -49,11 +53,8 @@ module Multicash
49
53
 
50
54
  def body
51
55
  lines = []
52
- transfers.reverse.each_with_index do |transfer|
53
- if transfer.valid?
54
- transfer.reference_counter += 1
55
- lines << transfer.generate
56
- end
56
+ transfers.each do |transfer|
57
+ lines << transfer.generate
57
58
  end
58
59
 
59
60
  lines.join("\x0C")
@@ -78,7 +78,6 @@ module Multicash
78
78
 
79
79
  def payment_system
80
80
  @payment_system.is_a?(Array) ? "/#{@payment_system.join("/")}" : "/#{@payment_system}"
81
-
82
81
  end
83
82
 
84
83
  private
data/multicash.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: multicash 0.0.2 ruby lib
5
+ # stub: multicash 0.0.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "multicash"
9
- s.version = "0.0.2"
9
+ s.version = "0.0.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Anton Yordanov"]
@@ -26,12 +26,17 @@ describe "Multicash::PaymentOrder" do
26
26
  context "generate" do
27
27
  subject { Multicash::PaymentOrder.new }
28
28
 
29
+ specify "increment transfer reference_counter" do
30
+ subject << transfer
31
+ expect(transfer.reference_counter).to eq(1)
32
+ subject << transfer
33
+ expect(transfer.reference_counter).to eq(2)
34
+ end
35
+
29
36
  specify "save to file" do
30
37
  subject << transfer
31
38
  subject << transfer
32
39
  file_name = subject.save_to_file
33
-
34
-
35
40
  expect(File.exist?(file_name)).to be_true
36
41
  end
37
42
  end
data/spec/payment_spec.rb CHANGED
@@ -13,12 +13,12 @@ describe "Multicash::Payment" do
13
13
  expect(Multicash::Payment.new(attributes)).to be_valid
14
14
  end
15
15
 
16
- it "not be valid if ammount is not valid" do
16
+ it "not valid if ammount is not valid" do
17
17
  attributes[:ammount] = Multicash::Ammount.new(value: 222.12222222, currency: 'BGN')
18
18
  expect(Multicash::Payment.new(attributes)).to_not be_valid
19
19
  end
20
20
 
21
- it "not be valid if charges are not in allowed range" do
21
+ it "not valid if charges are not in allowed range" do
22
22
  attributes[:charges] = 'FRR'
23
23
  expect(Multicash::Payment.new(attributes)).to_not be_valid
24
24
  end
@@ -19,7 +19,7 @@ describe "Multicash::Transfer" do
19
19
  let(:payment) { Multicash::Payment.new( ammount: ammount, details: 'Details', charges: 'SHA') }
20
20
 
21
21
  context "validations" do
22
- it "valid on valid initilization objects" do
22
+ it "valid on valid initilization attributes" do
23
23
  expect(Multicash::Transfer.new( ordering_account: ordering_account,
24
24
  destination_account: destination_account,
25
25
  payment: payment,
@@ -27,7 +27,7 @@ describe "Multicash::Transfer" do
27
27
  ).to be_valid
28
28
  end
29
29
 
30
- it "invalid on invalid ordering_account" do
30
+ it "invalid on invalid ordering_account attribute" do
31
31
  ordering_account.name = ''
32
32
 
33
33
  expect(Multicash::Transfer.new(ordering_account: ordering_account,
@@ -37,7 +37,7 @@ describe "Multicash::Transfer" do
37
37
  ).to_not be_valid
38
38
  end
39
39
 
40
- it "invalid on invalid destination_account" do
40
+ it "invalid on invalid destination_account attribute" do
41
41
  destination_account.name = ''
42
42
 
43
43
  expect(Multicash::Transfer.new(ordering_account: ordering_account,
@@ -47,7 +47,7 @@ describe "Multicash::Transfer" do
47
47
  ).to_not be_valid
48
48
  end
49
49
 
50
- it "invalid on invalid payment" do
50
+ it "invalid on invalid payment attribute" do
51
51
  payment.ammount.value = 'fffff'
52
52
 
53
53
  expect(Multicash::Transfer.new(ordering_account: ordering_account,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multicash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Yordanov