Module: CiPower::Export
- Included in:
- CipExport
- Defined in:
- lib/ci_power/export.rb
Overview
The module Export can be used to convert models into CI-Power-Interface format. It can be used as mixin in every existing class.
Example
<tt> class Foo
include CiPower::Export
def add_to_cip(data)
export_customer(
[address_record(data), dossier_data_record(data), debt_claim_record(data)]
)
end
def output_cip
output.each do |record|
puts record.to_cip
end
end
end </tt>
Instance Attribute Summary collapse
-
#date_format ⇒ Object
Returns the date_format.
-
#group_no ⇒ Object
readonly
Returns the group number or default value 0.
-
#output ⇒ Object
readonly
Returns the all added records or an empty array.
Instance Method Summary collapse
-
#action_record(attributes) ⇒ Object
Creates a new action record described by the
attributes
hash. -
#address_record(attributes) ⇒ Object
Creates a new address record described by the
attributes
hash. -
#communication_record(attributes) ⇒ Object
Creates a new communication record described by the
attributes
hash. -
#convert_date(date) ⇒ Object
Converts a date or time into a string with the defined date_format.
-
#debt_claim_record(attributes) ⇒ Object
Creates a new debt claim record described by the
attributes
hash. -
#debtor_data_record(attributes) ⇒ Object
Creates a debtor data address record described by the
attributes
hash. -
#dossier_data_record(attributes) ⇒ Object
Creates a new dossier data record described by the
attributes
hash. -
#export_customer(records) ⇒ Object
Adds a single record or an array of records to the output and increments the group number.
-
#export_to_file(file, records) ⇒ Object
Adds a single record or an array of records as a new line to the file and increments the group number.
-
#installment_plan_record(attributes) ⇒ Object
Creates a new installment plan record described by the
attributes
hash. -
#open_appointment_record(attributes) ⇒ Object
Creates a new open appointment record described by the
attributes
hash. -
#ordered_output ⇒ Object
Returns the all added records sorted by group number and record type or an empty array.
-
#process_data_record(attributes) ⇒ Object
Creates a new open appointment record described by the
attributes
hash.
Instance Attribute Details
#date_format ⇒ Object
Returns the date_format. If no date_format is defined the default date_format %Y%m%d is returned. This date_format is used to convert a date, time or datetime into a string.
53 54 55 |
# File 'lib/ci_power/export.rb', line 53 def date_format @date_format end |
#group_no ⇒ Object (readonly)
Returns the group number or default value 0. The method export_customer increments this group number by one on every call.
46 47 48 |
# File 'lib/ci_power/export.rb', line 46 def group_no @group_no end |
#output ⇒ Object (readonly)
Returns the all added records or an empty array. To add records to the output use the method export_customer.
32 33 34 |
# File 'lib/ci_power/export.rb', line 32 def output @output end |
Instance Method Details
#action_record(attributes) ⇒ Object
Creates a new action record described by the attributes
hash
95 96 97 |
# File 'lib/ci_power/export.rb', line 95 def action_record(attributes) record CiPower::Action.new, attributes end |
#address_record(attributes) ⇒ Object
Creates a new address record described by the attributes
hash
71 72 73 |
# File 'lib/ci_power/export.rb', line 71 def address_record(attributes) record CiPower::Address.new, attributes end |
#communication_record(attributes) ⇒ Object
Creates a new communication record described by the attributes
hash
77 78 79 |
# File 'lib/ci_power/export.rb', line 77 def communication_record(attributes) record CiPower::Communication.new, attributes end |
#convert_date(date) ⇒ Object
Converts a date or time into a string with the defined date_format
148 149 150 |
# File 'lib/ci_power/export.rb', line 148 def convert_date(date) date.strftime(date_format) if date.respond_to?(:strftime) end |
#debt_claim_record(attributes) ⇒ Object
Creates a new debt claim record described by the attributes
hash
89 90 91 |
# File 'lib/ci_power/export.rb', line 89 def debt_claim_record(attributes) record CiPower::DebtClaim.new, attributes end |
#debtor_data_record(attributes) ⇒ Object
Creates a debtor data address record described by the attributes
hash
83 84 85 |
# File 'lib/ci_power/export.rb', line 83 def debtor_data_record(attributes) record CiPower::DebtorData.new, attributes end |
#dossier_data_record(attributes) ⇒ Object
Creates a new dossier data record described by the attributes
hash
65 66 67 |
# File 'lib/ci_power/export.rb', line 65 def dossier_data_record(attributes) record CiPower::DossierData.new, attributes end |
#export_customer(records) ⇒ Object
Adds a single record or an array of records to the output and increments the group number
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ci_power/export.rb', line 119 def export_customer(records) if records.is_a?(Array) records.each do |record| add_to_output record end else add_to_output records end increment_group_no records end |
#export_to_file(file, records) ⇒ Object
Adds a single record or an array of records as a new line to the file and increments the group number
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ci_power/export.rb', line 133 def export_to_file(file, records) if records.is_a?(Array) records.each do |record| raise "Export class must be sub class of CiPower::Record" unless record.kind_of? CiPower::Record file.puts record.to_cip end else raise "Export class must be sub class of CiPower::Record" unless records.kind_of? CiPower::Record file.puts records.to_cip end increment_group_no end |
#installment_plan_record(attributes) ⇒ Object
Creates a new installment plan record described by the attributes
hash
113 114 115 |
# File 'lib/ci_power/export.rb', line 113 def installment_plan_record(attributes) record CiPower::InstallmentPlan.new, attributes end |
#open_appointment_record(attributes) ⇒ Object
Creates a new open appointment record described by the attributes
hash
101 102 103 |
# File 'lib/ci_power/export.rb', line 101 def open_appointment_record(attributes) record CiPower::OpenAppointment.new, attributes end |
#ordered_output ⇒ Object
Returns the all added records sorted by group number and record type or an empty array.
39 40 41 |
# File 'lib/ci_power/export.rb', line 39 def ordered_output output.sort { |rec1, rec2| "#{rec1.group_no}#{rec1.record_type}".to_i <=> "#{rec2.group_no}#{rec2.record_type}".to_i } end |
#process_data_record(attributes) ⇒ Object
Creates a new open appointment record described by the attributes
hash
107 108 109 |
# File 'lib/ci_power/export.rb', line 107 def process_data_record(attributes) record CiPower::ProcessData.new, attributes end |