iif-parser 2.0.1 → 2.1.0

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
  SHA256:
3
- metadata.gz: 656936d865f1ccbdc36401d0e952f202cbd9c9319e6056aff64500caefd50a5d
4
- data.tar.gz: 791300cf9f0a83c477d4f7e2a843d20e51419a2e3415c4ee5cab8e101a3ff6a1
3
+ metadata.gz: 97be851659e45159838b5701374f4132a7809ec7562b7af7005186ee050c3797
4
+ data.tar.gz: 21c15fcdd9fe26bb97a6fcae3d3530444e42affc28a1177c04a13e5bd94eb965
5
5
  SHA512:
6
- metadata.gz: c06a42a202982534a58ea24c5b6d877ab0f0583115e2fed0b7dea87129dd6072a0fc35c6009cbcb6291f956250f4820ba205a95ba4e52658b59ccb4b81331226
7
- data.tar.gz: 8565ae63a6b57849af3c9a0287301e16bc7342cf69d489f65645359bfbef8dd37b251adf9e495e7f9d53878f717966993c6716c99ea2d95a3fb626d23c387d80
6
+ metadata.gz: 9ef378d4b38f1d7f6d597629fa563c0ec0a762d647fadf66a662bd7ceb30c400587020918816950b919830a3cc19904ca79bb5578e0cdf96d464e387c19904b6
7
+ data.tar.gz: 4ef5f73f6ebddce4ad7db9789fc552a2894988659fd62c8a2b8a8ea868c973576a2ac9c492fe4f38681b60d76cbd281d47034ce3db5f78119e4f046ff4600355
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .ruby-version
12
12
  *.gem
13
13
  *.sess
14
+ .tool-versions
15
+ todo.txt
data/README.md CHANGED
@@ -44,7 +44,7 @@ puts i.transactions.first.entries
44
44
  ```
45
45
  #### See the [specs](https://github.com/minimul/iif-parser/blob/master/spec/iif/parser_spec.rb) for more examples
46
46
 
47
- #### Ruby support is >= 2.4
47
+ #### Ruby support is >= 2.7
48
48
 
49
49
  ## Installation
50
50
  Add this line to your application's Gemfile:
data/iif-parser.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_runtime_dependency "rchardet"
21
21
 
22
22
  spec.add_development_dependency "rspec", ">= 3.4.4"
23
+ spec.add_development_dependency "tabulo", "~> 2.0"
23
24
  spec.add_development_dependency "awesome_print"
24
25
  spec.add_development_dependency "bundler", ">= 1.9"
25
26
  spec.add_development_dependency "rake", ">= 12.3.3"
@@ -1,5 +1,5 @@
1
1
  module Iif
2
2
  class Parser
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
data/lib/iif/parser.rb CHANGED
@@ -37,7 +37,7 @@ module Iif
37
37
  def parse_line(line, opts = {})
38
38
  ar = line.split(/\t/)
39
39
  if ar.size == 1
40
- ar = CSV.parse_line(line, opts).map { |i| i == nil ? "" : i }
40
+ ar = CSV.parse_line(line, **opts).map { |i| i == nil ? "" : i }
41
41
  else
42
42
  ar.map! { |value| clean_field(value) }
43
43
  end
@@ -63,6 +63,7 @@ module Iif
63
63
  end
64
64
 
65
65
  def parse_data(fields)
66
+ return if @entries.last&.type == 'ENDTRNS' && fields[0] == 'ENDTRNS' # found a repeating ENDTRNS
66
67
  definition = @definitions[fields[0]]
67
68
  entry = Entry.new
68
69
  entry.type = fields[0]
@@ -70,7 +71,7 @@ module Iif
70
71
  next unless definition and definition[idx]
71
72
  entry.send(definition[idx] + "=", field)
72
73
  end
73
- entry.amount = BigDecimal(entry.amount.gsub(/(,)/,'')) unless entry.amount.to_s == ""
74
+ entry.amount = convert_amount(entry.amount) unless entry.amount.to_s == ""
74
75
  entry.date = convert_date(entry.date) if entry.date and not entry.date == ""
75
76
  @entries.push(entry)
76
77
  end
@@ -88,14 +89,23 @@ module Iif
88
89
  Date.new(year.to_i, ar[0], ar[1])
89
90
  end
90
91
 
92
+ def convert_amount(amount)
93
+ amount.gsub!(/(,)/,'')
94
+ if amount =~ /^--/
95
+ amount.slice!(0)
96
+ elsif amount =~ /^\(.*\)$/
97
+ amount.gsub!(/[()]/,'')
98
+ amount.prepend("-")
99
+ end
100
+ BigDecimal(amount)
101
+ end
102
+
91
103
  def create_transactions
92
104
  transaction = nil
93
105
  in_transaction = false
94
106
 
95
107
  @entries.each do |entry|
96
-
97
108
  case entry.type
98
-
99
109
  when "TRNS"
100
110
  if in_transaction
101
111
  @transactions.push(transaction)
@@ -103,11 +113,9 @@ module Iif
103
113
  end
104
114
  transaction = Transaction.new
105
115
  in_transaction = true
106
-
107
116
  when "ENDTRNS"
108
117
  @transactions.push(transaction)
109
118
  in_transaction = false
110
-
111
119
  end
112
120
 
113
121
  transaction.entries.push(entry) if in_transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iif-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2023-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rchardet
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.4.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: tabulo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: awesome_print
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +119,7 @@ homepage: https://github.com/minimul/iif-parser
105
119
  licenses:
106
120
  - MIT
107
121
  metadata: {}
108
- post_install_message:
122
+ post_install_message:
109
123
  rdoc_options: []
110
124
  require_paths:
111
125
  - lib
@@ -120,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0'
122
136
  requirements: []
123
- rubygems_version: 3.0.4
124
- signing_key:
137
+ rubygems_version: 3.1.6
138
+ signing_key:
125
139
  specification_version: 4
126
140
  summary: Basic IIF parser written in Ruby
127
141
  test_files: []