Class: ParseFiles
- Inherits:
-
Object
- Object
- ParseFiles
- Defined in:
- lib/tbr/parse_files.rb
Constant Summary collapse
- SERVICE_NUMBER =
0- SERVICE_GROUP =
1- SERVICE_NAME =
2- SERVICE_CC =
3- DH_INVOICE_DATE =
2- OBR_SERVICE_NUMBER =
6
Class Method Summary collapse
- .map_services(groups, services, services_list) ⇒ Object
- .parse_bill_file(services, call_type, bill_file) ⇒ Object
- .parse_services_file(services_file) ⇒ Object
Class Method Details
.map_services(groups, services, services_list) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tbr/parse_files.rb', line 28 def self.map_services(groups,services,services_list) services_list.each do |fields| next if !valid_fields(fields) group = groups.group(fields[SERVICE_GROUP]) service = services.service(fields[SERVICE_NUMBER]) service.name = fields[SERVICE_NAME] service.cost_centre = fields[SERVICE_CC] group.add_service(service) end Tbr.log.warn("Empty services list. All services will be classified as unassigned") if services.size == 0 end |
.parse_bill_file(services, call_type, bill_file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tbr/parse_files.rb', line 41 def self.parse_bill_file(services,call_type,bill_file) invoice_date = '' begin file = File.new(bill_file) file.each_line do |line| fields = line.split(',') service_number = fields[OBR_SERVICE_NUMBER] case fields[0] when "DH" invoice_date = fields[DH_INVOICE_DATE] when "DS" service = services.service(service_number) service_summary = ServiceSummary.new(line,call_type) service.add_service_summary(service_summary) when "DC" service = services.service(service_number) call_detail = CallDetail.new(line,call_type) service.add_call_detail(call_detail) end end if invoice_date.empty? = "Invalid billing file: #{bill_file}" Tbr.log.fatal() raise ArgumentError, end rescue Errno::ENOENT = "Error accessing billing file: #{bill_file}" Tbr.log.fatal() raise IOError, rescue ArgumentError => e = "Error parsing billing file: #{bill_file}" Tbr.log.fatal() unless e..start_with?('Invalid') raise ArgumentError, end invoice_date end |
.parse_services_file(services_file) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tbr/parse_files.rb', line 13 def self.parse_services_file(services_file) out = [] begin CSV.foreach(services_file) do |fields| out << fields if valid_fields(fields) end Tbr.log.warn("Empty or invalid services file: #{services_file}. All services will be classified as unassigned") if out.empty? rescue Errno::ENOENT = "Error accessing services file: #{services_file}" Tbr.log.error() raise IOError, end out end |