abank 0.2.9 → 0.3.4

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: 36171477026334dbce5da50183c84e693047db8fb387c1306308f254590793fc
4
- data.tar.gz: da568eeb037c6deb414981abed805596ae1034f94eee103948bfdec5da958734
3
+ metadata.gz: 862349d8ec53f6ad3415370e120ca04d89dc724e41251149473c5c50a5f4cb90
4
+ data.tar.gz: fae7d3fba89e53f8f8bdadaf8a096adc50cbedc8afb4770ea330a6a0bbab6bc6
5
5
  SHA512:
6
- metadata.gz: a9fbda092cf84a6ee8a2552fbd0ff363d482fd599a243d263d03374978e6ab819cfcd270dc3d0c67456c4b54ddcc126d161e45180888a38922d1a4d468dbfe35
7
- data.tar.gz: 69365abb9979d7ca48369451c8496708cee0d15a3f4a0ef73521daa608c0c9c94a67ce2e5a00c4f2656c40ed4b1386d3224ea26b2094a6879bb87f03b6a14b1f
6
+ metadata.gz: e61d65d1fa0a8dfeb47e8037e5f490c7637bd811206bd6c423bb6ef537bc318fa04cf383001fbcb8e95f8a31615baedc222e62049dc60cb641fc5d99b99a44b0
7
+ data.tar.gz: fd2034192ebc4608510d640986a13f3844cbce74c8ae6f637460131ca317701a2d4e212dba85214e0930591d8754d82e73d568f5eb028b1f6898501ae50e7c37
data/.travis.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  rvm:
5
- - 2.6.3
5
+ - 2.7.0
data/Gemfile.lock CHANGED
@@ -1,43 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.9)
4
+ abank (0.3.4)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
8
- yard
9
8
 
10
9
  GEM
11
10
  remote: https://rubygems.org/
12
11
  specs:
13
12
  addressable (2.7.0)
14
13
  public_suffix (>= 2.0.2, < 5.0)
15
- concurrent-ruby (1.1.7)
14
+ ast (2.4.2)
15
+ backport (1.1.2)
16
+ benchmark (0.1.1)
17
+ concurrent-ruby (1.1.8)
16
18
  declarative (0.0.20)
17
- declarative-option (0.1.0)
18
- faraday (1.0.1)
19
+ e2mmap (0.1.0)
20
+ faraday (1.4.1)
21
+ faraday-excon (~> 1.1)
22
+ faraday-net_http (~> 1.0)
23
+ faraday-net_http_persistent (~> 1.1)
19
24
  multipart-post (>= 1.2, < 3)
20
- google-api-client (0.43.0)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-excon (1.1.0)
27
+ faraday-net_http (1.0.1)
28
+ faraday-net_http_persistent (1.1.0)
29
+ google-apis-bigquery_v2 (0.9.0)
30
+ google-apis-core (~> 0.1)
31
+ google-apis-core (0.3.0)
21
32
  addressable (~> 2.5, >= 2.5.1)
22
- googleauth (~> 0.9)
33
+ googleauth (~> 0.14)
23
34
  httpclient (>= 2.8.1, < 3.0)
24
35
  mini_mime (~> 1.0)
25
36
  representable (~> 3.0)
26
37
  retriable (>= 2.0, < 4.0)
27
- signet (~> 0.12)
28
- google-cloud-bigquery (1.21.2)
38
+ rexml
39
+ signet (~> 0.14)
40
+ webrick
41
+ google-cloud-bigquery (1.31.0)
29
42
  concurrent-ruby (~> 1.0)
30
- google-api-client (~> 0.33)
43
+ google-apis-bigquery_v2 (~> 0.1)
31
44
  google-cloud-core (~> 1.2)
32
45
  googleauth (~> 0.9)
33
46
  mini_mime (~> 1.0)
34
- google-cloud-core (1.5.0)
47
+ google-cloud-core (1.6.0)
35
48
  google-cloud-env (~> 1.0)
36
49
  google-cloud-errors (~> 1.0)
37
- google-cloud-env (1.3.3)
50
+ google-cloud-env (1.5.0)
38
51
  faraday (>= 0.17.3, < 2.0)
39
- google-cloud-errors (1.0.1)
40
- googleauth (0.13.1)
52
+ google-cloud-errors (1.1.0)
53
+ googleauth (0.16.2)
41
54
  faraday (>= 0.17.3, < 2.0)
42
55
  jwt (>= 1.4, < 3.0)
43
56
  memoist (~> 0.16)
@@ -45,34 +58,87 @@ GEM
45
58
  os (>= 0.9, < 2.0)
46
59
  signet (~> 0.14)
47
60
  httpclient (2.8.3)
48
- jwt (2.2.2)
61
+ jaro_winkler (1.5.4)
62
+ jwt (2.2.3)
63
+ kramdown (2.3.1)
64
+ rexml
65
+ kramdown-parser-gfm (1.1.0)
66
+ kramdown (~> 2.0)
67
+ kwalify (0.7.2)
49
68
  memoist (0.16.2)
50
- mini_mime (1.0.2)
51
- mini_portile2 (2.4.0)
69
+ mini_mime (1.1.0)
70
+ mini_portile2 (2.5.1)
52
71
  multi_json (1.15.0)
53
72
  multipart-post (2.1.1)
54
- nokogiri (1.10.10)
55
- mini_portile2 (~> 2.4.0)
73
+ nokogiri (1.11.3)
74
+ mini_portile2 (~> 2.5.0)
75
+ racc (~> 1.4)
56
76
  os (1.1.1)
57
- public_suffix (4.0.5)
77
+ parallel (1.20.1)
78
+ parser (3.0.1.1)
79
+ ast (~> 2.4.1)
80
+ psych (3.3.1)
81
+ public_suffix (4.0.6)
82
+ racc (1.5.2)
83
+ rainbow (3.0.0)
58
84
  rake (12.3.3)
59
- representable (3.0.4)
85
+ reek (6.0.4)
86
+ kwalify (~> 0.7.0)
87
+ parser (~> 3.0.0)
88
+ psych (~> 3.1)
89
+ rainbow (>= 2.0, < 4.0)
90
+ regexp_parser (2.1.1)
91
+ representable (3.1.1)
60
92
  declarative (< 0.1.0)
61
- declarative-option (< 0.2.0)
93
+ trailblazer-option (>= 0.1.1, < 0.2.0)
62
94
  uber (< 0.2.0)
63
95
  retriable (3.1.2)
96
+ reverse_markdown (2.0.0)
97
+ nokogiri
98
+ rexml (3.2.5)
64
99
  roo (2.8.3)
65
100
  nokogiri (~> 1)
66
101
  rubyzip (>= 1.3.0, < 3.0.0)
102
+ rubocop (1.13.0)
103
+ parallel (~> 1.10)
104
+ parser (>= 3.0.0.0)
105
+ rainbow (>= 2.2.2, < 4.0)
106
+ regexp_parser (>= 1.8, < 3.0)
107
+ rexml
108
+ rubocop-ast (>= 1.2.0, < 2.0)
109
+ ruby-progressbar (~> 1.7)
110
+ unicode-display_width (>= 1.4.0, < 3.0)
111
+ rubocop-ast (1.5.0)
112
+ parser (>= 3.0.1.1)
113
+ ruby-progressbar (1.11.0)
114
+ ruby2_keywords (0.0.4)
67
115
  rubyzip (2.3.0)
68
- signet (0.14.0)
116
+ signet (0.15.0)
69
117
  addressable (~> 2.3)
70
118
  faraday (>= 0.17.3, < 2.0)
71
119
  jwt (>= 1.5, < 3.0)
72
120
  multi_json (~> 1.10)
73
- thor (1.0.1)
121
+ solargraph (0.40.4)
122
+ backport (~> 1.1)
123
+ benchmark
124
+ bundler (>= 1.17.2)
125
+ e2mmap
126
+ jaro_winkler (~> 1.5)
127
+ kramdown (~> 2.3)
128
+ kramdown-parser-gfm (~> 1.1)
129
+ parser (~> 3.0)
130
+ reverse_markdown (>= 1.0.5, < 3)
131
+ rubocop (>= 0.52)
132
+ thor (~> 1.0)
133
+ tilt (~> 2.0)
134
+ yard (~> 0.9, >= 0.9.24)
135
+ thor (1.1.0)
136
+ tilt (2.0.10)
137
+ trailblazer-option (0.1.1)
74
138
  uber (0.1.0)
75
- yard (0.9.25)
139
+ unicode-display_width (2.0.0)
140
+ webrick (1.7.0)
141
+ yard (0.9.26)
76
142
 
77
143
  PLATFORMS
78
144
  ruby
@@ -81,6 +147,10 @@ DEPENDENCIES
81
147
  abank!
82
148
  bundler
83
149
  rake (~> 12.0)
150
+ reek
151
+ rubocop
152
+ solargraph
153
+ yard
84
154
 
85
155
  BUNDLED WITH
86
156
  2.1.4
data/abank.gemspec CHANGED
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/abank/version'
3
+ require_relative('lib/abank/version')
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'abank'
7
- spec.version = Abank::VERSION
6
+ spec.name = 'abank'
7
+ spec.version = Abank::VERSION
8
8
  spec.authors = ['Hernâni Rodrigues Vaz']
9
9
  spec.email = ['hernanirvaz@gmail.com']
10
10
  spec.homepage = 'https://github.com/hernanirvaz/abank'
11
11
  spec.license = 'MIT'
12
-
13
12
  spec.summary = 'Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery.'
14
- spec.description = spec.summary + ' Permite apagar/recriar movimentos/rendas ja no bigquery. ' \
13
+ spec.description = "#{spec.summary} Permite apagar/recriar movimentos/rendas ja no bigquery. "\
15
14
  ' Permite ainda classificar movimentos no bigquery.'
16
15
 
16
+ spec.required_ruby_version = Gem::Requirement.new('~> 2.7')
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['yard.run'] = 'yard'
19
-
20
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+ spec.metadata['yard.run'] = 'yard'
21
19
 
22
20
  # Specify which files should be added to the gem when it is released.
23
21
  # The `git ls-files -z` loads files in RubyGem that have been added into git.
@@ -29,11 +27,14 @@ Gem::Specification.new do |spec|
29
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
28
  spec.require_paths = ['lib']
31
29
 
32
- spec.add_development_dependency 'bundler'
33
- spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency('bundler')
31
+ spec.add_development_dependency('rake')
32
+ spec.add_development_dependency('reek')
33
+ spec.add_development_dependency('rubocop')
34
+ spec.add_development_dependency('solargraph')
35
+ spec.add_development_dependency('yard')
34
36
 
35
- spec.add_dependency 'google-cloud-bigquery'
36
- spec.add_dependency 'roo'
37
- spec.add_dependency 'thor'
38
- spec.add_dependency 'yard'
37
+ spec.add_dependency('google-cloud-bigquery')
38
+ spec.add_dependency('roo')
39
+ spec.add_dependency('thor')
39
40
  end
data/lib/abank.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require('thor')
4
- require('abank/big')
5
- require('abank/contrato')
6
- require('abank/rendas')
7
- require('abank/folha')
4
+ require('abank/big1')
5
+ require('abank/big2')
6
+ require('abank/big3')
7
+ require('abank/folha1')
8
+ require('abank/folha2')
8
9
  require('abank/version')
9
10
 
10
11
  # @author Hernani Rodrigues Vaz
@@ -12,30 +13,19 @@ module Abank
12
13
  DR = "/home/#{`whoami`.chomp}/Downloads"
13
14
  BD = 'hernanilr.ab'
14
15
 
15
- class Error < StandardError; end
16
-
17
16
  # CLI para carregar folhas calculo comuns no bigquery
18
17
  class CLI < Thor
19
18
  desc 'tag', 'classifica movimentos'
20
19
  # classifica movimentos
21
20
  def tag
22
- Big.new.mv_classifica
21
+ Big.new(options.to_h).mv_classifica.ct_dados.re_insert
23
22
  end
24
23
 
25
24
  desc 'apagamv', 'apaga movimentos'
26
25
  option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
27
26
  # apaga movimentos
28
27
  def apagamv
29
- Big.new(k: options[:k]).mv_delete.mv_insert.re_work
30
- end
31
-
32
- desc 'criact', 'cria contrato arrendamento'
33
- option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
34
- option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
35
- option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
36
- # cria contrato arrendamento
37
- def criact
38
- Big.new(c: options[:c], t: options[:t], d: options[:d]).ct_cria
28
+ Big.new(options.transform_keys(&:to_sym)).mv_delete.ct_dados.re_insert
39
29
  end
40
30
 
41
31
  desc 'apagact', 'apaga contrato arrendamento'
@@ -43,50 +33,53 @@ module Abank
43
33
  option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
44
34
  # apaga contrato arrendamento
45
35
  def apagact
46
- Big.new(c: options[:c], t: options[:t]).ct_apaga
36
+ Big.new(options.transform_keys(&:to_sym)).ct_apaga
37
+ end
38
+
39
+ desc 'criact', 'cria contrato arrendamento'
40
+ option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
41
+ option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
42
+ option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
43
+ # cria contrato arrendamento
44
+ def criact
45
+ Big.new(options.transform_keys(&:to_sym)).ct_cria
47
46
  end
48
47
 
49
48
  desc 'recriact', 'atualiza rendas de contrato arrendamento'
50
49
  option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
51
- option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
52
50
  option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
51
+ option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
53
52
  # atualiza rendas de contrato arrendamento
54
53
  def recriact
55
- Big.new(c: options[:c], t: options[:t]).ct_apaga
56
- Big.new(c: options[:c], t: true, d: options[:d]).ct_cria
54
+ opc = options[:c]
55
+ Big.new(c: opc, t: options[:t]).ct_apaga
56
+ Big.new(c: opc, t: true, d: options[:d]).ct_cria
57
57
  end
58
58
 
59
59
  desc 'recriare', 'atualiza rendas dos contratos ativos'
60
60
  option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
61
61
  # atualiza rendas dos contratos ativos
62
62
  def recriare
63
- Big.new(t: options[:t]).re_atualiza
63
+ Big.new(options.transform_keys(&:to_sym)).re_atualiza
64
64
  end
65
65
 
66
66
  desc 'work', 'carrega/apaga dados da folha calculo'
67
67
  option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
68
68
  option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
69
69
  option :v, banner: 'DATA', default: '', desc: 'data valor para movimentos a carregar'
70
- option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
70
+ option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
71
71
  # carrega/apaga dados da folha calculo
72
72
  def work
73
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
74
- Folha.new(work_opc.merge(f: f)).processa_xls
73
+ Dir.glob("#{DR}/*.xlsx").sort.each do |file|
74
+ Folha.new(options.transform_keys(&:to_sym).merge(f: file, i: true)).processa_xls
75
75
  end
76
76
  end
77
77
 
78
78
  desc 'show', 'mostra dados da folha calculo'
79
79
  # mostra folha calculo
80
80
  def show
81
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
82
- Folha.new(f: f).processa_xls
83
- end
84
- end
85
-
86
- no_commands do
87
- # @return [Hash] opcoes trabalho com movimentos para work
88
- def work_opc
89
- { s: options[:s], e: options[:e], i: true, v: options[:v], g: options[:g] }
81
+ Dir.glob("#{DR}/*.xlsx").sort.each do |file|
82
+ Folha.new(options.merge(f: file)).processa_xls
90
83
  end
91
84
  end
92
85
 
data/lib/abank/big1.rb ADDED
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('google/cloud/bigquery')
4
+
5
+ module Abank
6
+ # @see Big
7
+ class Big
8
+ # @return [Hash] opcoes trabalho
9
+ attr_reader :opcao
10
+
11
+ # @return [Google::Cloud::Bigquery::Data] resultado do Structured Query Language (SQL) no bigquery
12
+ attr_reader :bqres
13
+
14
+ # @return [Integer] numero linhas afetadas pelo Data Manipulation Language (DML) no bigquery
15
+ attr_reader :bqnrs
16
+
17
+ # acesso a base dados abank no bigquery
18
+ #
19
+ # @param [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
20
+ # @option opcoes [String] :k ('') movimentos a apagar (keysin.mv)
21
+ # @option opcoes [String] :c ('') id contrato arrendamento (re)
22
+ # @option opcoes [String] :d ('') data inicio contrato arrendamento (re)
23
+ # @option opcoes [Boolean] :t (false) trabalha todas as rendas? (re)
24
+ # @return [Hash] opcoes trabalho
25
+ def initialize(opcoes = {})
26
+ @opcao = opcoes
27
+ opcao
28
+ end
29
+
30
+ # @return [Google::Cloud::Bigquery] API bigquery
31
+ def bqapi
32
+ @bqapi ||= Google::Cloud::Bigquery.new
33
+ end
34
+
35
+ # @return [String] movimentos a apagar (keysin.mv)
36
+ def mvkys
37
+ opcao[:k][/([-+]*\d)+(,[-+]*\d+)*/].to_s
38
+ end
39
+
40
+ # apaga movimentos & suas rendas associadas no bigquery
41
+ #
42
+ # @return [Big] acesso a base dados abank no bigquery
43
+ def mv_delete
44
+ @ctlct = []
45
+ unless mvkys.empty?
46
+ # obtem lista contratos arrendamento associados aos movimentos a apagar
47
+ @ctlct = sql("select distinct ct from #{BD}.mv where #{ky_mv} in(#{mvkys}) and substr(ct,1,1)='r'")
48
+
49
+ # apaga todas as rendas dos contratos arrendamento associados aos movimentos a apagar
50
+ opcao[:t] = true unless ctlct.empty?
51
+ re_apaga.mv_delete_dml
52
+ end
53
+ self
54
+ end
55
+
56
+ # apaga movimentos no bigquery
57
+ def mv_delete_dml
58
+ dml("delete from #{BD}.mv where #{ky_mv} in(#{mvkys})")
59
+ puts("MOVIMENTOS APAGADOS #{bqnrs}")
60
+ end
61
+
62
+ # (see CLI#tag)
63
+ def mv_classifica
64
+ dml("update #{BD}.mv set mv.ct=tt.nct from (select * from #{BD}.cl) as tt where #{ky_mv}=tt.ky")
65
+ puts("MOVIMENTOS CLASSIFICADOS #{bqnrs}")
66
+ @ctlct = sql("select distinct ct from #{BD}.re") if bqnrs.positive?
67
+ self
68
+ end
69
+
70
+ # @return [String] expressao sql da chave de movimentos
71
+ def ky_mv
72
+ 'FARM_FINGERPRINT(CONCAT(CAST(mv.nc as STRING),mv.ds,CAST(mv.dl as STRING),CAST(mv.vl as STRING)))'
73
+ end
74
+
75
+ # @param [String] cmd comando a executar
76
+ # @return [Google::Cloud::Bigquery::QueryJob] tarefa SQL/DML no bigquery
77
+ def job(cmd)
78
+ bqjob = bqapi.query_job(cmd)
79
+ bqjob.wait_until_done!
80
+ err = bqjob.error
81
+ puts(err['message']) if err
82
+ bqjob
83
+ end
84
+
85
+ # executa Structured Query Language (SQL) no bigquery
86
+ #
87
+ # @param (see job)
88
+ # @param [Array] erro resultado quando falha execucao
89
+ # @return [Google::Cloud::Bigquery::Data] resultado do SQL
90
+ def sql(cmd, erro = [])
91
+ # se job.failed? executa job(cmd).data => StandardError
92
+ @bqres = job(cmd).data
93
+ rescue StandardError
94
+ @bqres = erro
95
+ end
96
+
97
+ # executa Data Manipulation Language (DML) no bigquery
98
+ #
99
+ # @param (see job)
100
+ # @return [Integer] numero rows afetadas pelo DML
101
+ def dml(cmd)
102
+ # se job.failed? executa Integer(nil) => StandardError
103
+ @bqnrs = Integer(job(cmd).num_dml_affected_rows)
104
+ rescue StandardError
105
+ @bqnrs = 0
106
+ end
107
+ end
108
+ end