Class: Tbr::Processor
- Inherits:
-
Object
- Object
- Tbr::Processor
- Defined in:
- lib/tbr/processor.rb
Constant Summary collapse
- UNASSIGNED =
'Unassigned'- USAGE =
'usage: Tbr::Processor.new([ output: output_pathname, services: service_array, log: log_filename, replace: true/false, logo: logo_filename, original: original_filename ])'- LOG_DEFAULT =
'/tmp/tbr.log'- LOGO_DEFAULT =
File.join(File.dirname(__FILE__), '../logo.jpg')
Instance Attribute Summary collapse
-
#logo ⇒ Object
Returns the value of attribute logo.
-
#logpath ⇒ Object
readonly
Returns the value of attribute logpath.
-
#original ⇒ Object
Returns the value of attribute original.
-
#output ⇒ Object
Returns the value of attribute output.
-
#replace ⇒ Object
Returns the value of attribute replace.
-
#services ⇒ Object
Returns the value of attribute services.
Instance Method Summary collapse
- #import_services(services_file) ⇒ Object
-
#initialize(options = {}) ⇒ Processor
constructor
A new instance of Processor.
- #process(input) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Processor
Returns a new instance of Processor.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tbr/processor.rb', line 23 def initialize( = {}) raise ArgumentError, USAGE unless .class == Hash @log = Tbr.log @log.info('Initialising Telstra Billing Reporter') self.output = [:output] self.logo = [:logo] self.services = [:services] @replace = [:replace] || false @original = [:original] end |
Instance Attribute Details
#logo ⇒ Object
Returns the value of attribute logo.
21 22 23 |
# File 'lib/tbr/processor.rb', line 21 def logo @logo end |
#logpath ⇒ Object (readonly)
Returns the value of attribute logpath.
21 22 23 |
# File 'lib/tbr/processor.rb', line 21 def logpath @logpath end |
#original ⇒ Object
Returns the value of attribute original.
20 21 22 |
# File 'lib/tbr/processor.rb', line 20 def original @original end |
#output ⇒ Object
Returns the value of attribute output.
21 22 23 |
# File 'lib/tbr/processor.rb', line 21 def output @output end |
#replace ⇒ Object
Returns the value of attribute replace.
20 21 22 |
# File 'lib/tbr/processor.rb', line 20 def replace @replace end |
#services ⇒ Object
Returns the value of attribute services.
21 22 23 |
# File 'lib/tbr/processor.rb', line 21 def services @services end |
Instance Method Details
#import_services(services_file) ⇒ Object
36 37 38 |
# File 'lib/tbr/processor.rb', line 36 def import_services(services_file) @services = ParseFiles::parse_services_file(services_file) end |
#process(input) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tbr/processor.rb', line 63 def process(input) fname = @original || input # if anonymous tmp file used after upload @log.info("Processing Telstra Bill File: #{fname || 'nil'}") raise ArgumentError, 'Filename not provided' unless input.class == String unless File.exist?(input) = "Input file #{input} does not exist." @log.error() raise IOError, end @log.warn("All services will be classified as unassigned") if @services.empty? @log.info("Files being written to #{output}") @log.info("Extracting Call Types from #{fname}") call_type = CallType.new call_type.load(input) services = Services.new groups = Groups.new @log.info("Extracting billing data from #{fname}") ParseFiles.map_services(groups,services,@services) invoice_date = ParseFiles.parse_bill_file(services,call_type,input) @log.info("Building Unassigned group") group = groups.group(UNASSIGNED) services.each do |service| group.add_service(service) if service.name == UNASSIGNED end unassigned_count = groups.group(UNASSIGNED).size @log.warn("#{unassigned_count} unassigned services") if unassigned_count > 0 cf = CreateFiles.new(invoice_date,output,replace) cf.logo = @logo @log.info("Creating group summaries") groups.each do |group| @log.info("Creating summary for #{group.name}") cf.group_summary(group) end @log.info("Creating service details") services.each do |service| @log.info("Creating report for #{service.service_number}") cf.call_details(service) end @log.info("Creating cost centre summary") cost_centres = {} services.each do |service| cc = service.cost_centre unless cc.empty? cc_total = cost_centres[cc] || 0.0 cost_centres[cc] = cc_total + service.total end end cf.cost_centre_totals(cost_centres) @log.info("Creating service totals summary") cf.service_totals(services) @log.info("PDF report files can be found in #{cf.dir_full_root}.") @log.info("Telstra billing data extract completed.") end |