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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9be98f6189b13517bf847be2bdddc9ce7f68eb65
4
- data.tar.gz: 3e8ce045af515ed7d627a0e4ffca52b16b7e1059
3
+ metadata.gz: 38fbb6b78613770842a83df919e0652c421d8902
4
+ data.tar.gz: ec4669a8aed09afbbcb33dfff44bbad0ac3d1c98
5
5
  SHA512:
6
- metadata.gz: 49a002ffda0f1be07af7bb3e17e188b61c449e571f638a097c4c7ac64bc67b977a45e629aa9cba19a5108e5fb0a594a2121d584cd43aa0d34d270a351da0f4cf
7
- data.tar.gz: bbe6649cf4e9fa92e0e0ffb336b4617604939ab46467a2aa4fc2b3db4f0c77127b8b51226d72b757d7d8705838cdc4579fbe61713229d0e59875afaebfee4c3c
6
+ metadata.gz: 02f1d2fd376c43b074c9db571240e51dca041f4588b7b31c3c2e7807f91479e62a60a653f203b84f7fd5f9b256840d72a1b0f82d1d2f3bb141fa1e31cceeedc8
7
+ data.tar.gz: 471d96bdb4a0c00f7c4a151e80c2d3e8d7967b7304634605db6e3309fd3c0cbd63f7d5dd3297814a14da913ce0bd643ee48ab33e36631b4bd55ed75649545373
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
@@ -1,5 +1,21 @@
1
1
  require 'datev/version'
2
- require 'datev/account'
3
- require 'datev/booking'
4
- require 'datev/booking_export'
5
- require 'datev/account_export'
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'
@@ -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
- self.fields << Field.new(name, type, options, &block)
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
- self.attributes[name] = value
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
@@ -1,5 +1,3 @@
1
- require 'datev/base'
2
-
3
1
  module Datev
4
2
  class Account < Base
5
3
  # http://www.datev.de/dnlexom/client/app/index.html#/document/1036228/D103622800011
@@ -1,5 +1,3 @@
1
- require 'datev/base'
2
-
3
1
  module Datev
4
2
  class Booking < Base
5
3
  # http://www.datev.de/dnlexom/client/app/index.html#/document/1036228/D103622800010
@@ -1,5 +1,3 @@
1
- require 'datev/base'
2
-
3
1
  module Datev
4
2
  class Header < Base
5
3
  # 1
@@ -1,5 +1,3 @@
1
- require 'datev/base'
2
-
3
1
  module Datev
4
2
  class AccountHeader < Header
5
3
  self.default_attributes = {
@@ -1,5 +1,3 @@
1
- require 'datev/base'
2
-
3
1
  module Datev
4
2
  class BookingHeader < Header
5
3
  self.default_attributes = {
@@ -1,6 +1,3 @@
1
- require 'csv'
2
- require 'datev/header'
3
-
4
1
  module Datev
5
2
  class Export
6
3
  CSV_OPTIONS = { :col_sep => ';', :encoding => 'windows-1252' }
@@ -1,7 +1,3 @@
1
- require 'datev/export'
2
- require 'datev/account_header'
3
- require 'datev/account'
4
-
5
1
  module Datev
6
2
  class AccountExport < Export
7
3
  self.header_class = AccountHeader
@@ -1,7 +1,3 @@
1
- require 'datev/export'
2
- require 'datev/booking_header'
3
- require 'datev/booking'
4
-
5
1
  module Datev
6
2
  class BookingExport < Export
7
3
  self.header_class = BookingHeader
@@ -1,26 +1,17 @@
1
1
  module Datev
2
2
  class Field
3
- attr_accessor :name, :type, :options, :block
3
+ attr_accessor :name, :options, :block
4
4
 
5
- def initialize(name, type, options={}, &block)
5
+ def initialize(name, options={}, &block)
6
6
  unless name.is_a?(String)
7
- raise ArgumentError.new('Name param has to be a String')
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('Options param has to be a Hash')
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
@@ -1,3 +1,3 @@
1
1
  module Datev
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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-28 00:00:00.000000000 Z
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/booking.rb
110
- - lib/datev/booking_export.rb
111
- - lib/datev/booking_header.rb
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/header.rb
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: