datev 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/lib/datev.rb +20 -4
- data/lib/datev/base.rb +8 -11
- data/lib/datev/{account.rb → base/account.rb} +0 -2
- data/lib/datev/{booking.rb → base/booking.rb} +0 -2
- data/lib/datev/{header.rb → base/header.rb} +0 -2
- data/lib/datev/{account_header.rb → base/header/account_header.rb} +0 -2
- data/lib/datev/{booking_header.rb → base/header/booking_header.rb} +0 -2
- data/lib/datev/export.rb +0 -3
- data/lib/datev/{account_export.rb → export/account_export.rb} +0 -4
- data/lib/datev/{booking_export.rb → export/booking_export.rb} +0 -4
- data/lib/datev/field.rb +4 -62
- data/lib/datev/field/boolean_field.rb +15 -0
- data/lib/datev/field/date_field.rb +19 -0
- data/lib/datev/field/decimal_field.rb +24 -0
- data/lib/datev/field/integer_field.rb +20 -0
- data/lib/datev/field/string_field.rb +20 -0
- data/lib/datev/version.rb +1 -1
- metadata +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38fbb6b78613770842a83df919e0652c421d8902
|
4
|
+
data.tar.gz: ec4669a8aed09afbbcb33dfff44bbad0ac3d1c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f1d2fd376c43b074c9db571240e51dca041f4588b7b31c3c2e7807f91479e62a60a653f203b84f7fd5f9b256840d72a1b0f82d1d2f3bb141fa1e31cceeedc8
|
7
|
+
data.tar.gz: 471d96bdb4a0c00f7c4a151e80c2d3e8d7967b7304634605db6e3309fd3c0cbd63f7d5dd3297814a14da913ce0bd643ee48ab33e36631b4bd55ed75649545373
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
data/lib/datev.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
require 'datev/version'
|
2
|
-
|
3
|
-
require 'datev/
|
4
|
-
require 'datev/
|
5
|
-
require 'datev/
|
2
|
+
|
3
|
+
require 'datev/field'
|
4
|
+
require 'datev/field/string_field'
|
5
|
+
require 'datev/field/integer_field'
|
6
|
+
require 'datev/field/boolean_field'
|
7
|
+
require 'datev/field/decimal_field'
|
8
|
+
require 'datev/field/date_field'
|
9
|
+
|
10
|
+
require 'datev/base'
|
11
|
+
require 'datev/base/header'
|
12
|
+
require 'datev/base/header/account_header'
|
13
|
+
require 'datev/base/header/booking_header'
|
14
|
+
require 'datev/base/account'
|
15
|
+
require 'datev/base/booking'
|
16
|
+
|
17
|
+
require 'datev/export'
|
18
|
+
require 'datev/export/account_export'
|
19
|
+
require 'datev/export/booking_export'
|
20
|
+
|
21
|
+
require 'csv'
|
data/lib/datev/base.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'datev/field'
|
2
|
-
|
3
1
|
module Datev
|
4
2
|
class Base
|
5
3
|
class << self
|
@@ -19,20 +17,19 @@ module Datev
|
|
19
17
|
raise ArgumentError.new("Field '#{name}' already exists")
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
field_class = const_get("Datev::#{type.to_s.capitalize}Field")
|
21
|
+
self.fields << field_class.new(name, options, &block)
|
23
22
|
end
|
24
23
|
|
25
24
|
def self.field_by_name(name)
|
26
25
|
self.fields.find { |f| f.name == name }
|
27
26
|
end
|
28
27
|
|
29
|
-
attr_accessor :attributes
|
30
|
-
|
31
28
|
def initialize(attributes)
|
32
|
-
self.attributes = self.class.default_attributes || {}
|
33
|
-
|
34
29
|
raise ArgumentError.new('Hash required') unless attributes.is_a?(Hash)
|
35
30
|
|
31
|
+
@attributes = self.class.default_attributes || {}
|
32
|
+
|
36
33
|
# Check existing names and set value (if valid)
|
37
34
|
attributes.each_pair do |name,value|
|
38
35
|
unless field = self.class.field_by_name(name)
|
@@ -40,12 +37,12 @@ module Datev
|
|
40
37
|
end
|
41
38
|
|
42
39
|
field.validate!(value)
|
43
|
-
|
40
|
+
@attributes[name] = value
|
44
41
|
end
|
45
42
|
|
46
43
|
# Check for missing values
|
47
44
|
self.class.fields.select(&:required?).each do |field|
|
48
|
-
if attributes[field.name].nil?
|
45
|
+
if @attributes[field.name].nil?
|
49
46
|
raise ArgumentError.new("Value for field '#{field.name}' is required but missing")
|
50
47
|
end
|
51
48
|
end
|
@@ -55,12 +52,12 @@ module Datev
|
|
55
52
|
field = self.class.field_by_name(name)
|
56
53
|
raise ArgumentError.new("Field '#{name}' not found") unless field
|
57
54
|
|
58
|
-
attributes[field.name]
|
55
|
+
@attributes[field.name]
|
59
56
|
end
|
60
57
|
|
61
58
|
def output(context=nil)
|
62
59
|
self.class.fields.map do |field|
|
63
|
-
value = attributes[field.name]
|
60
|
+
value = @attributes[field.name]
|
64
61
|
field.output(value, context)
|
65
62
|
end
|
66
63
|
end
|
data/lib/datev/export.rb
CHANGED
data/lib/datev/field.rb
CHANGED
@@ -1,26 +1,17 @@
|
|
1
1
|
module Datev
|
2
2
|
class Field
|
3
|
-
attr_accessor :name, :
|
3
|
+
attr_accessor :name, :options, :block
|
4
4
|
|
5
|
-
def initialize(name,
|
5
|
+
def initialize(name, options={}, &block)
|
6
6
|
unless name.is_a?(String)
|
7
|
-
raise ArgumentError.new('
|
8
|
-
end
|
9
|
-
|
10
|
-
unless [:string, :decimal, :boolean, :date, :integer].include?(type)
|
11
|
-
raise ArgumentError.new('Type param not recognized')
|
7
|
+
raise ArgumentError.new("Argument 'name' has to be a String")
|
12
8
|
end
|
13
9
|
|
14
10
|
unless options.is_a?(Hash)
|
15
|
-
raise ArgumentError.new('
|
16
|
-
end
|
17
|
-
|
18
|
-
unless (options.keys - [:limit, :required, :format, :precision, :scale]).empty?
|
19
|
-
raise ArgumentError.new('Options param includes unknown key')
|
11
|
+
raise ArgumentError.new("Argument 'options' has to be a Hash")
|
20
12
|
end
|
21
13
|
|
22
14
|
self.name = name
|
23
|
-
self.type = type
|
24
15
|
self.options = options
|
25
16
|
|
26
17
|
if block_given?
|
@@ -32,58 +23,9 @@ module Datev
|
|
32
23
|
options[:required] == true
|
33
24
|
end
|
34
25
|
|
35
|
-
def format
|
36
|
-
options[:format]
|
37
|
-
end
|
38
|
-
|
39
|
-
def limit
|
40
|
-
options[:limit]
|
41
|
-
end
|
42
|
-
|
43
|
-
def precision
|
44
|
-
options[:precision]
|
45
|
-
end
|
46
|
-
|
47
|
-
def scale
|
48
|
-
options[:scale]
|
49
|
-
end
|
50
|
-
|
51
26
|
def validate!(value)
|
52
27
|
if value.nil?
|
53
28
|
raise ArgumentError.new("Value for field '#{name}' is required") if required?
|
54
|
-
else
|
55
|
-
case type
|
56
|
-
when :string
|
57
|
-
raise ArgumentError.new("Value given for field '#{name}' is not a String") unless value.is_a?(String)
|
58
|
-
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.length > limit
|
59
|
-
when :integer
|
60
|
-
raise ArgumentError.new("Value given for field '#{name}' is not an Integer") unless value.is_a?(Integer)
|
61
|
-
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.to_s.length > limit
|
62
|
-
when :decimal
|
63
|
-
raise ArgumentError.new("Value given for field '#{name}' is not a Decimal") unless value.is_a?(Numeric)
|
64
|
-
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if precision && value.to_s.length > precision+1
|
65
|
-
when :date
|
66
|
-
raise ArgumentError.new("Value given for field '#{name}' is not a Date or Time") unless value.is_a?(Time) || value.is_a?(Date)
|
67
|
-
when :boolean
|
68
|
-
raise ArgumentError.new("Value given for field '#{name}' is not a Boolean") unless [true, false].include?(value)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def output(value, context=nil)
|
74
|
-
return if value.nil?
|
75
|
-
|
76
|
-
case type
|
77
|
-
when :string
|
78
|
-
value.slice(0, limit || 255)
|
79
|
-
when :integer
|
80
|
-
value.to_s
|
81
|
-
when :decimal
|
82
|
-
("%.#{scale}f" % value).sub('.',',')
|
83
|
-
when :boolean
|
84
|
-
value ? 1 : 0
|
85
|
-
when :date
|
86
|
-
value.strftime(format)
|
87
29
|
end
|
88
30
|
end
|
89
31
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Datev
|
2
|
+
class BooleanField < Field
|
3
|
+
def validate!(value)
|
4
|
+
super
|
5
|
+
|
6
|
+
unless value.nil?
|
7
|
+
raise ArgumentError.new("Value given for field '#{name}' is not a Boolean") unless [true, false].include?(value)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def output(value, _context=nil)
|
12
|
+
value ? 1 : 0 unless value.nil?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Datev
|
2
|
+
class DateField < Field
|
3
|
+
def format
|
4
|
+
options[:format]
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate!(value)
|
8
|
+
super
|
9
|
+
|
10
|
+
if value
|
11
|
+
raise ArgumentError.new("Value given for field '#{name}' is not a Date or Time") unless value.is_a?(Time) || value.is_a?(Date)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def output(value, _context=nil)
|
16
|
+
value.strftime(format) if value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Datev
|
2
|
+
class DecimalField < Field
|
3
|
+
def precision
|
4
|
+
options[:precision]
|
5
|
+
end
|
6
|
+
|
7
|
+
def scale
|
8
|
+
options[:scale]
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate!(value)
|
12
|
+
super
|
13
|
+
|
14
|
+
if value
|
15
|
+
raise ArgumentError.new("Value given for field '#{name}' is not a Decimal") unless value.is_a?(Numeric)
|
16
|
+
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if precision && value.to_s.length > precision+1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def output(value, _context=nil)
|
21
|
+
("%.#{scale}f" % value).sub('.',',') if value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Datev
|
2
|
+
class IntegerField < Field
|
3
|
+
def limit
|
4
|
+
options[:limit]
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate!(value)
|
8
|
+
super
|
9
|
+
|
10
|
+
if value
|
11
|
+
raise ArgumentError.new("Value given for field '#{name}' is not an Integer") unless value.is_a?(Integer)
|
12
|
+
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.to_s.length > limit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def output(value, _context=nil)
|
17
|
+
value.to_s if value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Datev
|
2
|
+
class StringField < Field
|
3
|
+
def limit
|
4
|
+
options[:limit]
|
5
|
+
end
|
6
|
+
|
7
|
+
def validate!(value)
|
8
|
+
super
|
9
|
+
|
10
|
+
if value
|
11
|
+
raise ArgumentError.new("Value given for field '#{name}' is not a String") unless value.is_a?(String)
|
12
|
+
raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.length > limit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def output(value, _context=nil)
|
17
|
+
value.slice(0, limit || 255) if value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/datev/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,16 +102,21 @@ files:
|
|
102
102
|
- examples/EXTF_Buchungsstapel.csv
|
103
103
|
- examples/EXTF_Kontenbeschriftungen.csv
|
104
104
|
- lib/datev.rb
|
105
|
-
- lib/datev/account.rb
|
106
|
-
- lib/datev/account_export.rb
|
107
|
-
- lib/datev/account_header.rb
|
108
105
|
- lib/datev/base.rb
|
109
|
-
- lib/datev/
|
110
|
-
- lib/datev/
|
111
|
-
- lib/datev/
|
106
|
+
- lib/datev/base/account.rb
|
107
|
+
- lib/datev/base/booking.rb
|
108
|
+
- lib/datev/base/header.rb
|
109
|
+
- lib/datev/base/header/account_header.rb
|
110
|
+
- lib/datev/base/header/booking_header.rb
|
112
111
|
- lib/datev/export.rb
|
112
|
+
- lib/datev/export/account_export.rb
|
113
|
+
- lib/datev/export/booking_export.rb
|
113
114
|
- lib/datev/field.rb
|
114
|
-
- lib/datev/
|
115
|
+
- lib/datev/field/boolean_field.rb
|
116
|
+
- lib/datev/field/date_field.rb
|
117
|
+
- lib/datev/field/decimal_field.rb
|
118
|
+
- lib/datev/field/integer_field.rb
|
119
|
+
- lib/datev/field/string_field.rb
|
115
120
|
- lib/datev/version.rb
|
116
121
|
homepage: https://github.com/ledermann/datev
|
117
122
|
licenses:
|