ci_power 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,10 @@ module CiPower
16
16
  @date_format ||= '%Y%m%d'
17
17
  end
18
18
 
19
+ def date_format=(date_format)
20
+ @date_format = date_format
21
+ end
22
+
19
23
  def dossier_data_record(attributes)
20
24
  record CiPower::DossierData.new, attributes
21
25
  end
@@ -44,20 +48,32 @@ module CiPower
44
48
  record CiPower::OpenAppointment.new, attributes
45
49
  end
46
50
 
51
+ def installment_plan_record(attributes)
52
+ record CiPower::InstallmentPlan.new, attributes
53
+ end
54
+
47
55
  def export_customer(records)
48
- records.each do |record|
49
- raise "Export class must be sub class of CiPower::Record" unless record.kind_of? CiPower::Record
50
- output << record
56
+ if records.is_a?(Array)
57
+ records.each do |record|
58
+ add_to_output record
59
+ end
60
+ else
61
+ add_to_output records
51
62
  end
52
63
  increment_group_no
53
64
  records
54
65
  end
55
66
 
56
67
  def convert_date(date)
57
- date.strftime(date_format) if date.kind_of? Date
68
+ date.strftime(date_format) if date.respond_to?(:strftime)
58
69
  end
59
70
 
60
71
  private
72
+ def add_to_output(record)
73
+ raise "Export class must be sub class of CiPower::Record" unless record.kind_of? CiPower::Record
74
+ output << record
75
+ end
76
+
61
77
  def record(record, attributes)
62
78
  attributes.merge! :group_no => group_no
63
79
  attributes.each do |key, value|
@@ -0,0 +1,40 @@
1
+ module CiPower
2
+ class InstallmentPlan < Record
3
+ attr_accessor :no_of_installments,
4
+ :installment_amount,
5
+ :first_installment_date,
6
+ :period,
7
+ :interval,
8
+ :installment_fee,
9
+ :fixed_size_installment_amount,
10
+ :last_installment_date
11
+
12
+ def initialize(attributes = {})
13
+ if attributes.is_a? Hash
14
+ attributes.merge! :record_type => '15'
15
+ attributes.each do |key, value|
16
+ self.send("#{key}=".to_sym, value) if self.respond_to?("#{key}=")
17
+ end
18
+ end
19
+ end
20
+
21
+ def to_cip(with_line_terminator = true)
22
+ fill_up(
23
+ {
24
+ :record_type => 2,
25
+ :group_no => 7,
26
+ :address_identification_debtee => 25,
27
+ :address_identification_debtor => 25,
28
+ :no_of_installments => 3,
29
+ :installment_amount => 15,
30
+ :first_installment_date => 10,
31
+ :period => 10,
32
+ :interval => 3,
33
+ :installment_fee => 15,
34
+ :fixed_size_installment_amount => 1,
35
+ :last_installment_date => 10
36
+ }, with_line_terminator
37
+ )
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module CiPower
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.20"
3
3
  end
data/lib/ci_power.rb CHANGED
@@ -10,3 +10,4 @@ require "ci_power/debt_claim"
10
10
  require "ci_power/action"
11
11
  require "ci_power/open_appointment"
12
12
  require "ci_power/debtor_data"
13
+ require "ci_power/installment_plan"
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module CiPower
4
+ describe Export do
5
+ # created dummy class with module behaviour
6
+ let(:dummy_class) do
7
+ Class.new do
8
+ extend(CiPower::Export)
9
+ end
10
+ end
11
+
12
+ context "when module is included" do
13
+ it "output should an empty array" do
14
+ dummy_class.output.should be_instance_of Array
15
+ dummy_class.output.should be_empty
16
+ end
17
+
18
+ it "group_no should be 0" do
19
+ dummy_class.group_no.should == 0
20
+ end
21
+
22
+ it "data_format should be '%Y%m%d'" do
23
+ dummy_class.date_format.should == '%Y%m%d'
24
+ end
25
+ end
26
+
27
+ describe "#convert_date" do
28
+ it "when date is valid should convert date to format" do
29
+
30
+ unconverted_date = Time.local 2012, 7, 31
31
+
32
+ converted_date = dummy_class.convert_date(unconverted_date)
33
+ converted_date.should == "20120731"
34
+ end
35
+
36
+ it "when date is not valid do nothing" do
37
+ converted_date = dummy_class.convert_date("XXX")
38
+ converted_date.should be_nil
39
+ end
40
+ end
41
+
42
+ describe "#date_format" do
43
+ it "should change the date format" do
44
+ dummy_class.date_format = 'new_format'
45
+ dummy_class.date_format.should == 'new_format'
46
+ end
47
+
48
+ context "when the date format is changed" do
49
+ before(:each) { dummy_class.date_format = '%d-%m-%Y' }
50
+
51
+ it "should format the date with the new format" do
52
+ date_string = dummy_class.convert_date Time.local(2012, 7, 31)
53
+ date_string.should == "31-07-2012"
54
+ end
55
+ end
56
+ end
57
+
58
+ {:dossier_data_record => 'CiPower::DossierData',
59
+ :address_record => 'CiPower::Address',
60
+ :communication_record => 'CiPower::Communication',
61
+ :debtor_data_record => 'CiPower::DebtorData',
62
+ :debt_claim_record => 'CiPower::DebtClaim',
63
+ :action_record => 'CiPower::Action',
64
+ :open_appointment_record => 'CiPower::OpenAppointment',
65
+ :installment_plan_record => 'CiPower::InstallmentPlan'
66
+ }.each do |method, clazz|
67
+ describe "##{method.to_s}" do
68
+ it "generates a new instance of #{clazz}" do
69
+ record = dummy_class.send(method, :test => 'test')
70
+ record.should be_instance_of clazz.split("::").inject(Object) { |ref, clazz| ref::const_get(clazz) }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ module CiPower
4
+ describe InstallmentPlan do
5
+ describe "Functions" do
6
+ let(:installment_plan) do
7
+ InstallmentPlan.new :group_no => '1',
8
+ :address_identification_debtee => '123456',
9
+ :address_identification_debtor => '987654',
10
+ :no_of_installments => '4',
11
+ :installment_amount => '215',
12
+ :first_installment_date => '20120816',
13
+ :period => 'Month',
14
+ :interval => '2',
15
+ :installment_fee => '15',
16
+ :fixed_size_installment_amount => '0',
17
+ :last_installment_date => '20130416'
18
+
19
+ end
20
+
21
+ describe "#to_cip" do
22
+ it "record_type should be 15 on pos 1" do
23
+ installment_plan.to_cip[0..1].should == '15'
24
+ end
25
+ it "group_no should be 1 on pos 3" do
26
+ installment_plan.to_cip[2..8].strip.should == '1'
27
+ end
28
+ it "address_identification_debtee should be 123456 on pos 10" do
29
+ installment_plan.to_cip[9..33].strip.should == '123456'
30
+ end
31
+ it "address_identification_debtor should be 987654 on pos 35" do
32
+ installment_plan.to_cip[34..58].strip.should == '987654'
33
+ end
34
+ it "no_of_installments should be 4 on pos 60" do
35
+ installment_plan.to_cip[59..61].strip.should == '4'
36
+ end
37
+ it "installment_amount should be 215 on pos 63" do
38
+ installment_plan.to_cip[62..76].strip.should == '215'
39
+ end
40
+ it "first_installment_date should be 20120816 on pos 78" do
41
+ installment_plan.to_cip[77..86].strip.should == '20120816'
42
+ end
43
+ it "period should be Month on pos 88" do
44
+ installment_plan.to_cip[87..96].strip.should == 'Month'
45
+ end
46
+ it "interval should be 2 on pos 98" do
47
+ installment_plan.to_cip[97..99].strip.should == '2'
48
+ end
49
+ it "installment_fee should be 15 on pos 101" do
50
+ installment_plan.to_cip[100..114].strip.should == '15'
51
+ end
52
+ it "fixed_size_installment_amount should be 0 on pos 116" do
53
+ installment_plan.to_cip[115..115].strip.should == '0'
54
+ end
55
+ it "last_installment_date should be 20130416 on pos 117" do
56
+ installment_plan.to_cip[116..125].strip.should == '20130416'
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'ci_power'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata CHANGED
@@ -1,70 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ci_power
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.18
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.20
6
6
  platform: ruby
7
- authors:
8
- - Maik Duff
7
+ authors:
8
+ - Maik Duff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70301639919120 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70301639919120
12
+
13
+ date: 2012-08-15 00:00:00 +02: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
25
27
  description: Creates input files for CI-Power interface
26
- email:
27
- - md@impac.ch
28
+ email:
29
+ - md@impac.ch
28
30
  executables: []
31
+
29
32
  extensions: []
33
+
30
34
  extra_rdoc_files: []
31
- files:
32
- - lib/ci_power/action.rb
33
- - lib/ci_power/address.rb
34
- - lib/ci_power/communication.rb
35
- - lib/ci_power/debt_claim.rb
36
- - lib/ci_power/debtor_data.rb
37
- - lib/ci_power/dossier_data.rb
38
- - lib/ci_power/export.rb
39
- - lib/ci_power/open_appointment.rb
40
- - lib/ci_power/record.rb
41
- - lib/ci_power/version.rb
42
- - lib/ci_power.rb
43
- - lib/generators/ci_power/ci_power_generator.rb
44
- - lib/generators/ci_power/templates/cip_export.rb
45
- - lib/tasks/ci_power.rake
46
- homepage: ''
35
+
36
+ files:
37
+ - lib/ci_power.rb
38
+ - lib/ci_power/action.rb
39
+ - lib/ci_power/address.rb
40
+ - lib/ci_power/communication.rb
41
+ - lib/ci_power/debt_claim.rb
42
+ - lib/ci_power/debtor_data.rb
43
+ - lib/ci_power/dossier_data.rb
44
+ - lib/ci_power/export.rb
45
+ - lib/ci_power/installment_plan.rb
46
+ - lib/ci_power/open_appointment.rb
47
+ - lib/ci_power/record.rb
48
+ - lib/ci_power/version.rb
49
+ - lib/generators/ci_power/ci_power_generator.rb
50
+ - lib/generators/ci_power/templates/cip_export.rb
51
+ - lib/tasks/ci_power.rake
52
+ - spec/spec_helper.rb
53
+ - spec/ci_power/export_spec.rb
54
+ - spec/ci_power/installment_plan_spec.rb
55
+ has_rdoc: true
56
+ homepage: ""
47
57
  licenses: []
58
+
48
59
  post_install_message:
49
60
  rdoc_options: []
50
- require_paths:
51
- - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
53
65
  none: false
54
- requirements:
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: '0'
58
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
71
  none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
64
76
  requirements: []
77
+
65
78
  rubyforge_project: ci_power
66
- rubygems_version: 1.8.16
79
+ rubygems_version: 1.5.1
67
80
  signing_key:
68
81
  specification_version: 3
69
82
  summary: CI-Power Interface
70
- test_files: []
83
+ test_files:
84
+ - spec/spec_helper.rb
85
+ - spec/ci_power/export_spec.rb
86
+ - spec/ci_power/installment_plan_spec.rb