Module: CsvReport
- Defined in:
- lib/csv_report.rb,
lib/csv_report/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
Class Method Details
.calculating_report ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/csv_report.rb', line 33 def self.calculating_report @data.select do |row| @total_mins_cell_locals += ChronicDuration.parse(row['Duração']) if Helpers::CALL_LOCAL_CELL.include?(row['Tpserv']) @total_mins_cell_long_distants += ChronicDuration.parse(row['Duração']) if Helpers::CALL_DISTANTS_CELL.include?(row['Tpserv']) @total_mins_fixed_phone_locals += ChronicDuration.parse(row['Duração']) if Helpers::CALL_LOCAL_FIXED_PHONE.include?(row['Tpserv']) @total_mins_fixed_phone_long_distants += ChronicDuration.parse(row['Duração']) if Helpers::CALL_DISTANTS_FIXED_PHONE.include?(row['Tpserv']) @total_internet += BytesConverter::convert(row['Duração']) if Helpers::INTERNET_TIM.include?(row['Tpserv']) @total_sms += 1 if Helpers::TORPEDOS_TIM.include?(row['Tpserv']) end end |
.output_report ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/csv_report.rb', line 48 def self.output_report total_call_locals = (@total_mins_cell_locals + @total_mins_fixed_phone_locals) total_call_distants = (@total_mins_cell_long_distants + @total_mins_fixed_phone_long_distants) output = "\n1. Ligações Locais: #{ChronicDuration.output(total_call_locals, :keep_zero => true)}" output << "\n\ta. Para Celulares: #{ChronicDuration.output(@total_mins_cell_locals, :keep_zero => true)}" output << "\n\tb. Para Fixo: #{ChronicDuration.output(@total_mins_fixed_phone_locals, :keep_zero => true)}" output << "\n2. Ligações de Longa Distância: #{ChronicDuration.output(total_call_distants, :keep_zero => true)}" output << "\n\ta. Para Celulares: #{ChronicDuration.output(@total_mins_cell_long_distants, :keep_zero => true)}" output << "\n\tb. Para Fixo: #{ChronicDuration.output(@total_mins_fixed_phone_long_distants, :keep_zero => true)}" output << "\n3. SMS (unidades): #{@total_sms}" output << "\n4. Internet (bytes): #{@total_internet}" output end |
.report(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/csv_report.rb', line 7 def self.report(*args) @file = args[0] @num_account = args[1] @data = Array.new = {:headers => true, :col_sep => ';'} @total_mins_cell_locals, @total_mins_cell_long_distants = 0, 0 @total_mins_fixed_phone_locals, @total_mins_fixed_phone_long_distants = 0, 0 @total_sms, @total_internet = 0, 0 return "O caminho do arquivo .csv é obrigatório." if @file.nil? return "O número da conta é obrigatório." if @num_account.nil? begin CSV.foreach(@file, ) { |row| @data << row if row['NumAcs'] == @num_account } rescue return "Não foi possível ler o arquivo no diretório #{@file}." end return "Não foi encontrado registros com o numero #{@num_account}." if @data.count < 1 calculating_report puts output_report end |