sie 2.0.0 → 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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQ2NTU4OGIwMDIxOTQyN2FjNmZjMGY1MWUzYTBjOWY2YWNkODI4Zg==
4
+ MTZiMGU5Y2JlZWE3MjJkMDIxZGQ1NzQwNjlmZDRmZDk1YTYxMTk5Ng==
5
5
  data.tar.gz: !binary |-
6
- MTIzODUzYWQyN2ZjNTAwNWM0NDg0NTQyZjQ1ZTY2Mjc4YmM1MTYwOQ==
6
+ MTQzMTQ5ZTliZTc5NzA5ZGE5MWViNThkZjE1OTgwMGFkNTI3ODg5Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDUyNWIzZWNmZWE3NzA4NDEzYThkODNkNWViZjI2N2M3MjZhZDlkMWI2OTRl
10
- OGZlM2I2MzM4YzExODQ5ODg3Y2E0MDQxYTQ0Y2IzNTIyOGEyMmE1YmMxOWM2
11
- MDhhNDE1YjAzOGEzNWYyNzc0MmYwMDQ3ZDQ5ODEzYWU3Njk5ZDY=
9
+ NzRiMTUwZTEyMzhmOTE4YTE2ZGU0Zjg0ZTk1Mzc5MTM0MTI0YjNhODVmMGRm
10
+ ZTY2ZDFjZjFlM2YxZmQ4NGZkODIzZjhmNTRlNTY2NmMwZmE4NGVlNGM3Nzk0
11
+ MTYxNGRiNjRkZjE2ZWI4NzJhMTllOGNmMWVmYWRiMWFhYTZjZmI=
12
12
  data.tar.gz: !binary |-
13
- NmE4N2Q4MzY0YzljYzJkZWZhYjM0OTYyNzVjZWI5OTZiNmVmYWQ2MzY1MDZj
14
- YjNiNWJiNjg0Yzg4ZDMzMTQ3NDk2NTlhYjFiYWJkZDIyZTczOTFiNzlhMTY4
15
- NDY3OWI0NGRiYjNkZjQwMjg1MmQ5OGFjNGRjMWYzNTVhMjIzM2M=
13
+ MmExNTViM2VkY2M1OGExZmM4YjcwNzFhOTliNTQ1OWY5M2IzZjI0NzRlNjUx
14
+ YTdhZmNlNTlkYTI5OWFhNjNlZjIyYWRjMjhkZGMzNDkxZjc3MGM2MTMzMDdm
15
+ YWU2OWIwYTkwOGQ5NDU2NDc5N2Y1MDU0ZWY3ZGExMTBiYmZmYTg=
data/README.md CHANGED
@@ -78,8 +78,11 @@ class YourDataSource
78
78
  def each_voucher(&block)
79
79
  [
80
80
  {
81
- creditor: false, type: :invoice, number: 1,
82
- booked_on: Date.today, description: "Invoice 1",
81
+ # "creditor" and "type" is used to find the series, you can replace
82
+ # that with "series" if the automatic lookup doesn't work for you.
83
+ creditor: false, type: :invoice,
84
+
85
+ number: 1, booked_on: Date.today, description: "Invoice 1",
83
86
  voucher_lines: [
84
87
  {
85
88
  account_number: 1500, amount: 512.0,
@@ -2,10 +2,11 @@ require "stringio"
2
2
 
3
3
  class Sie::Document::Renderer
4
4
  EMPTY_ARRAY = :empty_array
5
+ ENCODING = Encoding::CP437
5
6
 
6
7
  def initialize
7
8
  @io = StringIO.new
8
- @io.set_encoding(Encoding::CP437)
9
+ @io.set_encoding(ENCODING)
9
10
  end
10
11
 
11
12
  def add_line(label, *values)
@@ -28,13 +29,17 @@ class Sie::Document::Renderer
28
29
  private
29
30
 
30
31
  def append(text)
31
- io.puts(text)
32
+ io.puts(encoded(text))
32
33
  end
33
34
 
34
35
  def format_values(values)
35
36
  values.map { |value| format_value(value) }
36
37
  end
37
38
 
39
+ def encoded(text)
40
+ text.encode(ENCODING, :invalid => :replace, :undef => :replace, :replace => "?")
41
+ end
42
+
38
43
  def format_value(value)
39
44
  case value
40
45
  when Date
data/lib/sie/document.rb CHANGED
@@ -71,16 +71,18 @@ module Sie
71
71
  end
72
72
  end
73
73
 
74
-
75
74
  def add_voucher(opts)
76
- creditor = opts.fetch(:creditor)
77
- type = opts.fetch(:type)
78
- number = opts.fetch(:number)
79
- booked_on = opts.fetch(:booked_on)
80
- description = opts.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
81
- voucher_lines = opts.fetch(:voucher_lines)
82
-
83
- add_line("VER", voucher_series(creditor, type), number, booked_on, description)
75
+ number = opts.fetch(:number)
76
+ booked_on = opts.fetch(:booked_on)
77
+ description = opts.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
78
+ voucher_lines = opts.fetch(:voucher_lines)
79
+ voucher_series = opts.fetch(:series) {
80
+ creditor = opts.fetch(:creditor)
81
+ type = opts.fetch(:type)
82
+ VoucherSeries.for(creditor, type)
83
+ }
84
+
85
+ add_line("VER", voucher_series, number, booked_on, description)
84
86
 
85
87
  add_array do
86
88
  voucher_lines.each do |line|
@@ -112,9 +114,5 @@ module Sie
112
114
  def financial_years
113
115
  data_source.financial_years.sort_by { |date_range| date_range.first }.reverse
114
116
  end
115
-
116
- def voucher_series(creditor, type)
117
- VoucherSeries.for(creditor, type)
118
- end
119
117
  end
120
118
  end
data/lib/sie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sie
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Sie::Document::Renderer, "#add_line" do
6
+ it "replaces input of the wrong encoding with '?'" do
7
+ renderer = Sie::Document::Renderer.new
8
+ renderer.add_line "Hello ☃", 1
9
+ output = renderer.render
10
+
11
+ expect(output).to eq "#Hello ? 1\n"
12
+ end
13
+ end
@@ -195,6 +195,18 @@ describe Sie::Document, "#render" do
195
195
  end
196
196
  end
197
197
 
198
+ context "with a series defined" do
199
+ let(:vouchers) {
200
+ [
201
+ build_voucher(series: "X"),
202
+ ]
203
+ }
204
+
205
+ it "reads the series from the voucher" do
206
+ expect(indexed_entry("ver", 0).attributes["serie"]).to eq("X")
207
+ end
208
+ end
209
+
198
210
  private
199
211
 
200
212
  def build_voucher(attributes)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barsoom AB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_extras
@@ -115,6 +115,7 @@ files:
115
115
  - spec/fixtures/sie_file.se
116
116
  - spec/integration/parser_spec.rb
117
117
  - spec/spec_helper.rb
118
+ - spec/unit/document/renderer_spec.rb
118
119
  - spec/unit/document/voucher_series_spec.rb
119
120
  - spec/unit/document_spec.rb
120
121
  - spec/unit/parser/line_parser_spec.rb
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
141
  version: '0'
141
142
  requirements: []
142
143
  rubyforge_project:
143
- rubygems_version: 2.2.1
144
+ rubygems_version: 2.4.5
144
145
  signing_key:
145
146
  specification_version: 4
146
147
  summary: Parses and generates SIE files (http://sie.se/)
@@ -148,6 +149,7 @@ test_files:
148
149
  - spec/fixtures/sie_file.se
149
150
  - spec/integration/parser_spec.rb
150
151
  - spec/spec_helper.rb
152
+ - spec/unit/document/renderer_spec.rb
151
153
  - spec/unit/document/voucher_series_spec.rb
152
154
  - spec/unit/document_spec.rb
153
155
  - spec/unit/parser/line_parser_spec.rb