abank 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe42ec73c07ba6f4abf94508dc67437f705c50cb46d7d09af11021cc1f7703f5
4
- data.tar.gz: 32c5f363db91cd879e78d057c11e7922688e673efe60f30c6735c03374792a34
3
+ metadata.gz: dfafd89334ba22494cd76823700f9d375a0fcab669d72a0cb121a3426a443559
4
+ data.tar.gz: 84542147e657fc2efe63a4bf19b647503744304225e9743361ebe8ebb28a373b
5
5
  SHA512:
6
- metadata.gz: 9607a89115e68861cc4930f7d0f97dbee7fa89fff98776a15665243285ff7c65faa505ddedf134e57a3d860c8f8bb15b968915e4fa1e77ecff2fbaa82d01a72e
7
- data.tar.gz: 07b58ce54df64fb237af774438b90ca68907c42f7c4683031546dcbb538da5e73912faa8553c606d52fcd3614e86b2fa65ccd4e8d4193a9aac073faa46ebe099
6
+ metadata.gz: 30d86a66d727250e1f63d46b1b440d7cac058eca820a261bb478943c6cb99d2144fd35a002a12430977f36568f72b66ef1685e6e822ef74529f8934ded77014a
7
+ data.tar.gz: 1beb1e721d5079d98759251beb6a6900a99090d10e698d066e2b651abec65ae4efc68360b0e7396c753beb90edfa4c6cb2d9204dfe9ccf3df055c6c4638651e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.1.2)
4
+ abank (0.1.3)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
data/README.md CHANGED
@@ -20,10 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- $ abank mostra # mostra dados do xlsx
24
- $ abank load # carrega dados xlsx no bigquery
23
+ $ abank mostra # mostra dados da folha calculo
24
+ $ abank load # carrega dados da folha calculo no bigquery
25
25
  $ abank classifica # classifica arquivo no bigquery
26
- $ abank halp # ajuda aos comandos
26
+ $ abank help [COMANDO] # ajuda aos comandos
27
27
 
28
28
  ## Development
29
29
 
data/lib/abank.rb CHANGED
@@ -12,19 +12,25 @@ module Abank
12
12
 
13
13
  # CLI para carregar folhas calculo comuns no bigquery
14
14
  class CLI < Thor
15
- desc 'load', 'carrega dados xlsx no bigquery'
15
+ desc 'load', 'carrega dados da folha calculo no bigquery'
16
16
  option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
17
17
  desc: 'Onde procurar folhas calculo'
18
18
  option :x, banner: 'EXT', default: '.xlsx',
19
19
  desc: 'Extensao das folhas calculo'
20
+ option :s, type: :boolean, default: false,
21
+ desc: 'apaga linhas similares no bigquery'
22
+ option :e, type: :boolean, default: false,
23
+ desc: 'apaga linhas existentes no bigquery'
20
24
  # processa xlsx
21
25
  def load
26
+ # opcoes apagar linhas
27
+ d = options.select { |_, v| [true, false].include?(v) }
22
28
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
23
- Bigquery.new(f).processa
29
+ Bigquery.new(f, d).processa
24
30
  end
25
31
  end
26
32
 
27
- desc 'mostra', 'mostra dados do xlsx'
33
+ desc 'mostra', 'mostra dados da folha calculo'
28
34
  option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
29
35
  desc: 'Onde procurar folhas calculo'
30
36
  option :x, banner: 'EXT', default: '.xlsx',
@@ -39,7 +45,7 @@ module Abank
39
45
  desc 'classifica', 'classifica arquivo no bigquery'
40
46
  # classifica bigquery
41
47
  def classifica
42
- Bigquery.new('').sql_update
48
+ Bigquery.new.sql_update
43
49
  end
44
50
 
45
51
  default_task :mostra
@@ -20,14 +20,20 @@ module Abank
20
20
  attr_reader :sql
21
21
  # @return [Integer] numero conta
22
22
  attr_reader :num
23
+ # @return [Hash<String, Boolean>] opcoes apagar linhas
24
+ attr_reader :apaga
23
25
 
24
26
  # permite processa folhas calculo comuns no bigquery
25
27
  #
26
28
  # @param [String] xls folha calculo para processar
29
+ # @param [Hash<String, Boolean>] apaga opcoes apagar linhas
30
+ # @option apaga [Boolean] s apaga linhas similares sim/nao?
31
+ # @option apaga [Boolean] e apaga linhas existentes sim/nao?
27
32
  # @return [Bigquery] acesso folha calculo & bigquery
28
- def initialize(xls)
33
+ def initialize(xls = '', apaga = {})
29
34
  @book = Roo::Spreadsheet.open(xls) if xls.size.positive?
30
35
  @num = xls.match?(/card/i) ? 2 : 1
36
+ @apaga = apaga
31
37
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
32
38
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
33
39
  @api = Google::Cloud::Bigquery.new
@@ -56,12 +62,15 @@ module Abank
56
62
  #
57
63
  # @return [Array<Hash>] resultado sql
58
64
  def sql_select
59
- s = "select * from ab.mv where nc=#{num}" \
60
- " and dl='#{row[0].strftime(DF)}'" \
61
- " and vl=#{row[3]}"
62
-
63
65
  # se array.count > 1 => nao fazer nada
64
- @sql = job_bigquery?(s) ? [{}, {}] : job.data
66
+ @sql = job_bigquery?('select * ' + sql_where) ? [{}, {}] : job.data
67
+ end
68
+
69
+ # @return [String] parte sql para processamento linhas similares
70
+ def sql_where
71
+ "from ab.mv where nc=#{num}" \
72
+ " and dl='#{row[0].strftime(DF)}'" \
73
+ " and vl=#{row[3]}"
65
74
  end
66
75
 
67
76
  # classifica linhas
@@ -84,5 +93,10 @@ module Abank
84
93
  def sql_insert_calculado
85
94
  ",#{row[1].year},#{row[1].month},null,'#{row[3].positive? ? 'c' : 'd'}')"
86
95
  end
96
+
97
+ # @return [Integer] numero linhas apagadas
98
+ def sql_delete
99
+ dml('delete ' + sql_where + " and ds='#{sql.first[:ds].strip}'")
100
+ end
87
101
  end
88
102
  end
@@ -9,7 +9,7 @@ module Abank
9
9
  # prepara linha folha calculo para processamento
10
10
  #
11
11
  # @param [Hash] has da linha em processamento
12
- def corrige_dados(has)
12
+ def corrige_hash(has)
13
13
  @row = has.values
14
14
  @row[2] = row[2].strip
15
15
  @row[3] = -1 * row[3] if num > 1
@@ -38,23 +38,23 @@ module Abank
38
38
 
39
39
  # processa linha folha calculo para arquivo
40
40
  #
41
- # @param (see corrige_dados)
41
+ # @param (see corrige_hash)
42
42
  # @return [String] linha folha calculo processada
43
43
  def processa_row(has)
44
- corrige_dados(has)
44
+ corrige_hash(has)
45
45
  sql_select
46
46
  if rnaoexiste? then row_str + (sql_insert == 1 ? ' NOVA' : ' ERRO')
47
- elsif rexiste? then row_existente
48
47
  elsif rsimila? then row_similar
48
+ elsif rexiste? then row_existente
49
49
  end
50
50
  end
51
51
 
52
52
  # obtem linha folha calculo para apresentacao
53
53
  #
54
- # @param (see corrige_dados)
54
+ # @param (see corrige_hash)
55
55
  # @return (see row_str)
56
56
  def show_row(has)
57
- corrige_dados(has)
57
+ corrige_hash(has)
58
58
  row_str
59
59
  end
60
60
 
@@ -66,12 +66,14 @@ module Abank
66
66
 
67
67
  # @return [String] linha folha calculo similar
68
68
  def row_similar
69
- row_str + " PARECIDA #{sql.first[:ds].strip}"
69
+ d = apaga['s'] ? sql_delete : 0
70
+ row_str + " SIMILAR#{d.zero? ? ' ' : ' APAGADA '}#{sql.first[:ds].strip}"
70
71
  end
71
72
 
72
73
  # @return [String] linha folha calculo existente
73
74
  def row_existente
74
- row_str + ' EXISTE'
75
+ d = apaga['e'] ? sql_delete : 0
76
+ row_str + " EXISTENTE#{d.zero? ? '' : ' APAGADA'}"
75
77
  end
76
78
 
77
79
  # @return [Boolean] linha folha calculo nao existe no bigquery?
data/lib/abank/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Abank
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-15 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler