ci_power 0.0.2

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.
@@ -0,0 +1,95 @@
1
+ module CiPower
2
+ class Address < Record
3
+ attr_accessor :new_order_id,
4
+ :address_type_company,
5
+ :title,
6
+ :salutation,
7
+ :lastname,
8
+ :firstname,
9
+ :name_affix,
10
+ :address,
11
+ :po_box,
12
+ :postal_code,
13
+ :city,
14
+ :country,
15
+ :contact_salutation,
16
+ :contact_lastname,
17
+ :contact_firstname,
18
+ :language,
19
+ :method_of_payment,
20
+ :account_no,
21
+ :commercial_register_no,
22
+ :vat_no,
23
+ :industry,
24
+ :region,
25
+ :reserve_field,
26
+ :customer_specific_field_1,
27
+ :customer_specific_field_2,
28
+ :customer_specific_field_3,
29
+ :customer_specific_field_4,
30
+ :customer_specific_field_5,
31
+ :customer_specific_field_6,
32
+ :customer_specific_field_7,
33
+ :customer_specific_field_8,
34
+ :customer_specific_field_9,
35
+ :customer_specific_field_10,
36
+ :customer_specific_field_11,
37
+ :customer_specific_field_12,
38
+ :customer_specific_field_13,
39
+ :customer_specific_field_14,
40
+ :customer_specific_field_15,
41
+ :customer_specific_field_16
42
+
43
+ def initialize(attributes = {})
44
+ if attributes.is_a? Hash
45
+ attributes.merge! :record_type => '01'
46
+ attributes.each do |key, value|
47
+ self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=")
48
+ end
49
+ end
50
+ end
51
+
52
+ def to_cip
53
+ cip_default_data << fill_up(
54
+ address_type_company => 1,
55
+ title => 32,
56
+ salutation => 10,
57
+ lastname => 32,
58
+ firstname => 32,
59
+ name_affix => 32,
60
+ address => 32,
61
+ po_box => 32,
62
+ postal_code => 10,
63
+ city => 32,
64
+ country => 10,
65
+ contact_salutation => 10,
66
+ contact_lastname => 32,
67
+ contact_firstname => 32,
68
+ language => 10,
69
+ method_of_payment => 10,
70
+ account_no => 32,
71
+ commercial_register_no => 15,
72
+ vat_no => 15,
73
+ industry => 10,
74
+ region => 10,
75
+ reserve_field => 10,
76
+ customer_specific_field_1 => 10,
77
+ customer_specific_field_2 => 10,
78
+ customer_specific_field_3 => 10,
79
+ customer_specific_field_4 => 32,
80
+ customer_specific_field_5 => 32,
81
+ customer_specific_field_6 => 64,
82
+ customer_specific_field_7 => 64,
83
+ customer_specific_field_8 => 64,
84
+ customer_specific_field_9 => 64,
85
+ customer_specific_field_10 => 64,
86
+ customer_specific_field_11 => 64,
87
+ customer_specific_field_12 => 64,
88
+ customer_specific_field_13 => 64,
89
+ customer_specific_field_14 => 64,
90
+ customer_specific_field_15 => 64,
91
+ customer_specific_field_16 => 64
92
+ )
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,19 @@
1
+ module CiPower
2
+ class Communication < Record
3
+ attr_accessor :type,
4
+ :text
5
+
6
+ def initialize(attributes = {})
7
+ if attributes.is_a? Hash
8
+ attributes.merge! :record_type => '02'
9
+ attributes.each do |key, value|
10
+ self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=")
11
+ end
12
+ end
13
+ end
14
+
15
+ def to_cip
16
+ cip_default_data << fill_up(type => 10, text => 32)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ module CiPower
2
+ class DebtClaim < Record
3
+ attr_accessor :op_no,
4
+ :amount_type,
5
+ :value_date,
6
+ :amount,
7
+ :invoice_date,
8
+ :invoice_text,
9
+ :dossier_currency,
10
+ :exchange_rate,
11
+ :customer_specific_field_1,
12
+ :customer_specific_field_2,
13
+ :customer_specific_field_3,
14
+ :customer_specific_field_4,
15
+ :customer_specific_field_5,
16
+ :customer_specific_field_6,
17
+ :customer_specific_field_7,
18
+ :customer_specific_field_8,
19
+ :customer_specific_field_9,
20
+ :customer_specific_field_10,
21
+ :customer_specific_field_11,
22
+ :customer_specific_field_12,
23
+ :customer_specific_field_13,
24
+ :customer_specific_field_14,
25
+ :customer_specific_field_15
26
+
27
+ def initialize(attributes = {})
28
+ if attributes.is_a? Hash
29
+ attributes.merge! :record_type => '11'
30
+ attributes.each do |key, value|
31
+ self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=")
32
+ end
33
+ end
34
+ end
35
+
36
+ def amount
37
+ @amount.abs
38
+ end
39
+
40
+ def amount_type
41
+ @amount_type ||= @amount < 0 ? 'GU-GL' : 'RG-GL'
42
+ end
43
+
44
+ def to_cip
45
+ cip_default_data << fill_up(
46
+ op_no => 25,
47
+ amount_type => 10,
48
+ value_date => 10,
49
+ amount => 15,
50
+ invoice_date => 10,
51
+ invoice_text => 32,
52
+ customer_specific_field_1 => 32,
53
+ customer_specific_field_2 => 32,
54
+ dossier_currency => 10,
55
+ exchange_rate => 15,
56
+ customer_specific_field_3 => 32,
57
+ customer_specific_field_4 => 32,
58
+ customer_specific_field_5 => 32,
59
+ customer_specific_field_6 => 32,
60
+ customer_specific_field_7 => 32,
61
+ customer_specific_field_8 => 32,
62
+ customer_specific_field_9 => 32,
63
+ customer_specific_field_10 => 32,
64
+ customer_specific_field_11 => 32,
65
+ customer_specific_field_12 => 32,
66
+ customer_specific_field_13 => 32,
67
+ customer_specific_field_14 => 32,
68
+ customer_specific_field_15 => 32
69
+ )
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,89 @@
1
+ module CiPower
2
+ class DossierData < Record
3
+ attr_accessor :debt_claim_reason,
4
+ :reference_1,
5
+ :ikv,
6
+ :feature_1,
7
+ :feature_2,
8
+ :interest_rate,
9
+ :currency,
10
+ :notes,
11
+ :external_dossier_no,
12
+ :reference_2,
13
+ :reference_3,
14
+ :reference_4,
15
+ :customer_specific_field_1,
16
+ :customer_specific_field_2,
17
+ :customer_specific_field_3,
18
+ :customer_specific_field_4,
19
+ :customer_specific_field_5,
20
+ :customer_specific_field_6,
21
+ :customer_specific_field_7,
22
+ :customer_specific_field_8,
23
+ :customer_specific_field_9,
24
+ :customer_specific_field_10,
25
+ :customer_specific_field_11,
26
+ :customer_specific_field_12,
27
+ :customer_specific_field_13,
28
+ :customer_specific_field_14,
29
+ :customer_specific_field_15,
30
+ :customer_specific_field_16,
31
+ :customer_specific_field_17,
32
+ :customer_specific_field_18,
33
+ :customer_specific_field_19,
34
+ :customer_specific_field_20
35
+
36
+ def initialize(attributes = {})
37
+ if attributes.is_a? Hash
38
+ attributes.merge! :record_type => '10'
39
+ attributes.each do |key, value|
40
+ self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=")
41
+ end
42
+ end
43
+ end
44
+
45
+ def to_cip
46
+ fill_up(
47
+ record_type => 2,
48
+ group_no => 7,
49
+ address_identification_debtee => 25,
50
+ '' => 25,
51
+ address_identification_debtor => 25,
52
+ debt_claim_reason => 64,
53
+ reference_1 => 32,
54
+ ikv => 10,
55
+ feature_1 => 10,
56
+ '' => 22,
57
+ feature_2 => 10,
58
+ '' => 22,
59
+ interest_rate => 10,
60
+ currency => 10,
61
+ notes => 240,
62
+ external_dossier_no => 32,
63
+ reference_2 => 32,
64
+ reference_3 => 32,
65
+ reference_4 => 32,
66
+ customer_specific_field_1 => 10,
67
+ customer_specific_field_2 => 10,
68
+ customer_specific_field_3 => 10,
69
+ customer_specific_field_4 => 32,
70
+ customer_specific_field_5 => 32,
71
+ customer_specific_field_6 => 32,
72
+ customer_specific_field_7 => 32,
73
+ customer_specific_field_8 => 32,
74
+ customer_specific_field_9 => 32,
75
+ customer_specific_field_10 => 32,
76
+ customer_specific_field_11 => 32,
77
+ customer_specific_field_12 => 32,
78
+ customer_specific_field_13 => 32,
79
+ customer_specific_field_14 => 32,
80
+ customer_specific_field_15 => 32,
81
+ customer_specific_field_16 => 32,
82
+ customer_specific_field_17 => 32,
83
+ customer_specific_field_18 => 32,
84
+ customer_specific_field_19 => 32,
85
+ customer_specific_field_20 => 32
86
+ )
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,61 @@
1
+ module CiPower
2
+ module Export
3
+ attr :output
4
+ attr :group_no
5
+ attr :date_format, true
6
+
7
+ def output
8
+ @output ||= []
9
+ end
10
+
11
+ def group_no
12
+ @group_no ||= 0
13
+ end
14
+
15
+ def date_format
16
+ @date_format ||= '%Y%m%d'
17
+ end
18
+
19
+ def dossier_data_record(attributes)
20
+ record CiPower::DossierData.new, attributes
21
+ end
22
+
23
+ def address_record(attributes)
24
+ record CiPower::Address.new, attributes
25
+ end
26
+
27
+ def communication_record(attributes)
28
+ record CiPower::Communication.new, attributes
29
+ end
30
+
31
+ def debt_claim_record(attributes)
32
+ record CiPower::DebtClaim.new, attributes
33
+ end
34
+
35
+ def export_customer(records)
36
+ records.each do |record|
37
+ raise "Export class must be sub class of CiPower::Record" unless record.kind_of? CiPower::Record
38
+ output << record
39
+ end
40
+ increment_group_no
41
+ end
42
+
43
+ def convert_date(date)
44
+ date.strftime(date_format) if date.kind_of? Date
45
+ end
46
+
47
+ private
48
+ def record(record, attributes)
49
+ attributes.merge! :group_no => group_no
50
+ attributes.each do |key, value|
51
+ method_name = "#{key}=".to_sym
52
+ record.send(method_name, value) if record.respond_to? method_name
53
+ end
54
+ record
55
+ end
56
+
57
+ def increment_group_no
58
+ @group_no = group_no + 1
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ module CiPower
2
+ class Record
3
+ attr_accessor :record_type,
4
+ :group_no,
5
+ :address_identification_debtee,
6
+ :address_identification_debtor
7
+
8
+ def cip_default_data
9
+ fill_up(record_type => 2, group_no => 7, address_identification_debtee => 25, address_identification_debtor => 25)
10
+ end
11
+
12
+ def fill_up(data)
13
+ line = ""
14
+ if data.is_a? Hash
15
+ data.each do |field, length|
16
+ field = field.to_s unless field.is_a? String
17
+ line << field.ljust(length)
18
+ end
19
+ end
20
+ line + line_terminator
21
+ end
22
+
23
+ def line_terminator
24
+ "\n"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module CiPower
2
+ VERSION = "0.0.2"
3
+ end
data/lib/ci_power.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "ci_power/version"
2
+
3
+ require "ci_power/export"
4
+
5
+ require "ci_power/record"
6
+ require "ci_power/dossier_data"
7
+ require "ci_power/address"
8
+ require "ci_power/communication"
9
+ require "ci_power/debt_claim"
@@ -0,0 +1,12 @@
1
+ module CiPower
2
+ module Generators
3
+ class CiPowerGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "This generator creates a model file at app/models"
7
+ def generate_cip_export
8
+ copy_file "cip_export.rb", "app/models/cip_export.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ class CipExport
2
+ include CiPower::Export
3
+
4
+ def initialize(output)
5
+ # Define mapping for CI-Power export here. For example:
6
+ #
7
+ # Add dossier_data
8
+ # output << dossier_data(:reference_1 => '99999', :interest_rate => '15')
9
+ #
10
+ # Add communication
11
+ # output << communication(:type => 'T1', :text => '0812502850')
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ namespace :ci_power do
2
+ OUTPUT_FILE = 'tmp/ci_power_export.txt'
3
+
4
+ desc 'Extract data from application'
5
+ task :extract_data => :environment do
6
+ @content = CipExport.new.output.sort_by { |a| [a.group_no, a.record_type] }
7
+ end
8
+
9
+ desc 'Export data into output file'
10
+ task :export => :extract_data do
11
+ File.open(OUTPUT_FILE, "w+") do |file|
12
+ @content.each do |line|
13
+ file.puts line.to_cip
14
+ end
15
+ end
16
+ end
17
+
18
+ desc 'Removes output file'
19
+ task :clean do
20
+ rm OUTPUT_FILE
21
+ end
22
+
23
+ task :default => "ci_power:export"
24
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci_power
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Maik Duff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-12-02 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ description: Creates input files for CI-Power interface
28
+ email:
29
+ - md@impac.ch
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - lib/ci_power.rb
38
+ - lib/ci_power/address.rb
39
+ - lib/ci_power/communication.rb
40
+ - lib/ci_power/debt_claim.rb
41
+ - lib/ci_power/dossier_data.rb
42
+ - lib/ci_power/export.rb
43
+ - lib/ci_power/record.rb
44
+ - lib/ci_power/version.rb
45
+ - lib/generators/ci_power/ci_power_generator.rb
46
+ - lib/generators/ci_power/templates/cip_export.rb
47
+ - lib/tasks/ci_power.rake
48
+ has_rdoc: true
49
+ homepage: ""
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: ci_power
72
+ rubygems_version: 1.5.1
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: CI-Power Interface
76
+ test_files: []
77
+