datev 0.1.1 → 0.2.0

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: 2c321a3bfeae671bbfdb6873b7b75bb34887f453
4
- data.tar.gz: dbe77e04243cdb4afa3dbd9ee26bb2867b4cedf9
3
+ metadata.gz: 956e90c7d3a49baf12d3337b605381daa3e20d87
4
+ data.tar.gz: 172c44ef62e75de78b96dec23b6db196e466ba2e
5
5
  SHA512:
6
- metadata.gz: bfb8ba8f87cb539f9c9bc3ba446449752ade2c1295eba4baf4d183d210cf3f6c3648cc4f4c781e6e625a8ea0824eba39ca51a7120a99b4b4045379971894367d
7
- data.tar.gz: f6511e6f062388127bc692fa0d3d4359d1bbe53c8e432c0caae018fa82a64978956966da96b1e19d1862469fa675d0280b39a908fd887014439192ea1c32f4cd
6
+ metadata.gz: cdcda8fd8dc40c21fe94ef4430eb29a962d0cfb6f8d78ac63f91e2ae7ca935a003be7b820d6fa7602601a23dd59efa97cb37a9e13fc7adcfc268c0e7579d2d2a
7
+ data.tar.gz: 90c7657ff7d11bce0598678d6f41e4d12bdb99a2ff216c76c43e5fdbba482bd705fb54d230371fee262f7adb0854e09e6cdca9717854587e4ca73e696bff4997
data/README.md CHANGED
@@ -4,6 +4,7 @@ Ruby gem for exporting bookings to DATEV via CSV file
4
4
 
5
5
  [![Build Status](https://travis-ci.org/ledermann/datev.svg?branch=master)](https://travis-ci.org/ledermann/datev)
6
6
  [![Code Climate](https://codeclimate.com/github/ledermann/datev/badges/gpa.svg)](https://codeclimate.com/github/ledermann/datev)
7
+ [![Coverage Status](https://coveralls.io/repos/github/ledermann/datev/badge.svg?branch=master)](https://coveralls.io/github/ledermann/datev?branch=master)
7
8
 
8
9
  ## Installation
9
10
 
@@ -35,7 +36,7 @@ export = Datev::Export.new(
35
36
  'Bezeichnung' => 'Beispiel-Buchungen'
36
37
  ) # For available hash keys see /lib/datev/header.rb
37
38
 
38
- export << Datev::Booking.new(
39
+ export << {
39
40
  'Belegdatum' => Date.new(2016,6,21),
40
41
  'Buchungstext' => 'Fachbuch: Controlling für Dummies',
41
42
  'Umsatz (ohne Soll/Haben-Kz)' => 24.95,
@@ -43,9 +44,9 @@ export << Datev::Booking.new(
43
44
  'Konto' => 1200,
44
45
  'Gegenkonto (ohne BU-Schlüssel)' => 4940,
45
46
  'BU-Schlüssel' => '8'
46
- ) # For available hash keys see /lib/datev/booking.rb
47
+ } # For available hash keys see /lib/datev/booking.rb
47
48
 
48
- export << Datev::Booking.new(
49
+ export << {
49
50
  'Belegdatum' => Date.new(2016,6,22),
50
51
  'Buchungstext' => 'Honorar FiBu-Seminar',
51
52
  'Umsatz (ohne Soll/Haben-Kz)' => 5950.00,
@@ -53,7 +54,7 @@ export << Datev::Booking.new(
53
54
  'Konto' => 10000,
54
55
  'Gegenkonto (ohne BU-Schlüssel)' => 8400,
55
56
  'Belegfeld 1' => 'RE201606-135'
56
- )
57
+ }
57
58
 
58
59
  export.to_file('EXTF_Buchungsstapel.csv')
59
60
  ```
data/datev.gemspec CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'coveralls'
26
28
  end
data/lib/datev/base.rb CHANGED
@@ -13,7 +13,7 @@ module Datev
13
13
 
14
14
  # Check if there is already a field with the same name
15
15
  if self.fields.find { |f| f.name == name }
16
- raise ArgumentError.new("Field #{name} already exists")
16
+ raise ArgumentError.new("Field '#{name}' already exists")
17
17
  end
18
18
 
19
19
  self.fields << Field.new(name, type, options)
@@ -22,10 +22,12 @@ module Datev
22
22
  def initialize(attributes)
23
23
  self.attributes = {}
24
24
 
25
- # Check existing name and set value (if valid)
25
+ raise ArgumentError.new('Hash required') unless attributes.is_a?(Hash)
26
+
27
+ # Check existing names and set value (if valid)
26
28
  attributes.each_pair do |name,value|
27
29
  unless field = self.class.fields.find { |f| f.name == name }
28
- raise ArgumentError.new("Field #{name} not found")
30
+ raise ArgumentError.new("Field '#{name}' not found")
29
31
  end
30
32
 
31
33
  field.validate!(value)
@@ -35,7 +37,7 @@ module Datev
35
37
  # Check for missing values
36
38
  self.class.fields.select(&:required?).each do |field|
37
39
  if attributes[field.name].nil?
38
- raise ArgumentError.new("Field #{field.name} is required but missing")
40
+ raise ArgumentError.new("Value for field '#{field.name}' is required but missing")
39
41
  end
40
42
  end
41
43
  end
data/lib/datev/export.rb CHANGED
@@ -12,7 +12,7 @@ module Datev
12
12
  'Datenkategorie' => 21,
13
13
  'Formatname' => 'Buchungsstapel',
14
14
  'Formatversion' => 7,
15
- 'Erzeugt am' => Time.now,
15
+ 'Erzeugt am' => Time.now.utc,
16
16
  'Sachkontenlänge' => 4,
17
17
  'Bezeichnung' => 'Buchungen',
18
18
  'Buchungstyp' => 1,
@@ -20,14 +20,14 @@ module Datev
20
20
  }
21
21
 
22
22
  def initialize(header_attributes)
23
+ raise ArgumentError.new('Hash required') unless header_attributes.is_a?(Hash)
24
+
23
25
  @header = Header.new DEFAULT_HEADER_ATTRIBUTES.merge(header_attributes)
24
26
  @rows = []
25
27
  end
26
28
 
27
- def <<(booking)
28
- raise ArgumentError.new('Param must be a Datev::Booking instance') unless booking.is_a?(Booking)
29
-
30
- @rows << booking
29
+ def <<(attributes)
30
+ @rows << Datev::Booking.new(attributes)
31
31
  end
32
32
 
33
33
  def to_s
data/lib/datev/field.rb CHANGED
@@ -36,29 +36,38 @@ module Datev
36
36
  options[:limit]
37
37
  end
38
38
 
39
+ def precision
40
+ options[:precision]
41
+ end
42
+
43
+ def scale
44
+ options[:scale]
45
+ end
46
+
39
47
  def validate!(value)
40
- if value
48
+ if value.nil?
49
+ raise ArgumentError.new("Value for field '#{name}' is required") if required?
50
+ else
41
51
  case type
42
52
  when :string
43
- raise ArgumentError.new("Field '#{name}' is not a String") unless value.is_a?(String)
44
- raise ArgumentError.new("Value '#{value}' fo field '#{name}' is too long") if limit && value.length > limit
53
+ raise ArgumentError.new("Value given for field '#{name}' is not a String") unless value.is_a?(String)
54
+ raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.length > limit
45
55
  when :integer
46
- raise ArgumentError.new("Field '#{name}' is not an Integer") unless value.is_a?(Integer)
47
- raise ArgumentError.new("Value '#{value}' fo field '#{name}' is too long") if limit && value.to_s.length > limit
56
+ raise ArgumentError.new("Value given for field '#{name}' is not an Integer") unless value.is_a?(Integer)
57
+ raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if limit && value.to_s.length > limit
48
58
  when :decimal
49
- raise ArgumentError.new("Field '#{name}' is not a Numeric") unless value.is_a?(Numeric)
59
+ raise ArgumentError.new("Value given for field '#{name}' is not a Decimal") unless value.is_a?(Numeric)
60
+ raise ArgumentError.new("Value '#{value}' for field '#{name}' is too long") if precision && value.to_s.length > precision+1
50
61
  when :date
51
- raise ArgumentError.new("Field '#{name}' is not a Date or Time") unless value.is_a?(Time) || value.is_a?(Date)
62
+ raise ArgumentError.new("Value given for field '#{name}' is not a Date or Time") unless value.is_a?(Time) || value.is_a?(Date)
52
63
  when :boolean
53
- raise ArgumentError.new("Field '#{name}' is not a Boolean") unless [true, false].include?(value)
64
+ raise ArgumentError.new("Value given for field '#{name}' is not a Boolean") unless [true, false].include?(value)
54
65
  end
55
- elsif required?
56
- raise ArgumentError.new("Field '#{name}' is required")
57
66
  end
58
67
  end
59
68
 
60
69
  def output(value)
61
- return unless value
70
+ return if value.nil?
62
71
 
63
72
  case type
64
73
  when :string
@@ -66,7 +75,7 @@ module Datev
66
75
  when :integer
67
76
  value.to_s.rjust(limit, '0')
68
77
  when :decimal
69
- value.to_s.sub('.',',')
78
+ ("%#{precision - scale - 1}.#{scale}f" % value).sub('.',',')
70
79
  when :boolean
71
80
  value ? 1 : 0
72
81
  when :date
data/lib/datev/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Datev
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Ledermann
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Provides an easy way to create CSV files which can be imported into accounting
56
84
  applications
57
85
  email: