abank 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 357eabd6927351fcd006bf58dda24c7b323395749b4ab6ef4ecf6f596a126241
4
- data.tar.gz: 0c3fc3b9e2ebda8bfe13b0ba072f50b0ff303668dfde4ffa7378e04f1470b81e
3
+ metadata.gz: 38252e611997b04e79e9743c3e9027906a47b3eb9252cf2a0d26526fe957d422
4
+ data.tar.gz: 927a605ae99f62cd66439d0f5468bb2da4ba2174ac9d3b7888fe72bda4dc6043
5
5
  SHA512:
6
- metadata.gz: b11a19c0f7039ff253776441e4f7b7de443808c4bf90dfec078a65dab3342b40197017d36e69d30d09d35500afd6e187ebe7113580e36ef921737085599c26af
7
- data.tar.gz: 98daf017bef2b5860fe498c9f11f6881374ebaa87451a10bf24fe1fa95006230c734a6dc1176e036983ec0e991777e59cfebaa34f2c2bc67828d3b95563163ae
6
+ metadata.gz: 0dc5655f4c39df0465f00506df19c87b81359c1d2c7ac5fe910b8daf25bd6aa2c59514693437bed6d35dc2c90ef022ab703afc3c14db18e38672fd90fd67318d
7
+ data.tar.gz: 5f97e3013d807922e1e6cc18d0636f5f02dbe0e0d83485520a582ab285915f7f71f44b526ad45a16f8931251c3c94d0f0453903db720570b89770a8d8d3fec4f
@@ -1,33 +1,15 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
  EnabledByDefault: true
4
4
 
5
- Style/ClassAndModuleChildren:
6
- EnforcedStyle: compact
7
-
8
5
  Style/Copyright:
9
- Enabled: false
10
-
11
- Style/DocumentationMethod:
12
- Enabled: false
6
+ Enabled: false
13
7
 
14
- Style/MethodCallWithArgsParentheses:
15
- Enabled: false
8
+ Lint/ConstantResolution:
9
+ Enabled: false
16
10
 
17
11
  Style/ConstantVisibility:
18
- Enabled: false
19
-
20
- Layout/MultilineMethodArgumentLineBreaks:
21
- Enabled: false
22
-
23
- Layout/MultilineHashKeyLineBreaks:
24
- Enabled: false
25
-
26
- Layout/FirstMethodParameterLineBreak:
27
- Enabled: false
28
-
29
- Layout/FirstHashElementLineBreak:
30
- Enabled: false
12
+ Enabled: false
31
13
 
32
- Style/MissingElse:
33
- Enabled: false
14
+ Style/EmptyElse:
15
+ EnforcedStyle: nil
@@ -1,43 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.5)
4
+ abank (0.3.1)
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.6)
16
- declarative (0.0.10)
14
+ ast (2.4.1)
15
+ backport (1.1.2)
16
+ benchmark (0.1.0)
17
+ concurrent-ruby (1.1.7)
18
+ declarative (0.0.20)
17
19
  declarative-option (0.1.0)
18
- faraday (1.0.1)
20
+ e2mmap (0.1.0)
21
+ faraday (1.1.0)
19
22
  multipart-post (>= 1.2, < 3)
20
- google-api-client (0.40.1)
23
+ ruby2_keywords
24
+ google-api-client (0.50.0)
21
25
  addressable (~> 2.5, >= 2.5.1)
22
26
  googleauth (~> 0.9)
23
27
  httpclient (>= 2.8.1, < 3.0)
24
28
  mini_mime (~> 1.0)
25
29
  representable (~> 3.0)
26
30
  retriable (>= 2.0, < 4.0)
31
+ rexml
27
32
  signet (~> 0.12)
28
- google-cloud-bigquery (1.21.1)
33
+ google-cloud-bigquery (1.25.0)
29
34
  concurrent-ruby (~> 1.0)
30
- google-api-client (~> 0.33)
35
+ google-api-client (~> 0.47)
31
36
  google-cloud-core (~> 1.2)
32
37
  googleauth (~> 0.9)
33
38
  mini_mime (~> 1.0)
34
39
  google-cloud-core (1.5.0)
35
40
  google-cloud-env (~> 1.0)
36
41
  google-cloud-errors (~> 1.0)
37
- google-cloud-env (1.3.2)
42
+ google-cloud-env (1.4.0)
38
43
  faraday (>= 0.17.3, < 2.0)
39
44
  google-cloud-errors (1.0.1)
40
- googleauth (0.12.0)
45
+ googleauth (0.14.0)
41
46
  faraday (>= 0.17.3, < 2.0)
42
47
  jwt (>= 1.4, < 3.0)
43
48
  memoist (~> 0.16)
@@ -45,33 +50,79 @@ GEM
45
50
  os (>= 0.9, < 2.0)
46
51
  signet (~> 0.14)
47
52
  httpclient (2.8.3)
48
- jwt (2.2.1)
53
+ jaro_winkler (1.5.4)
54
+ jwt (2.2.2)
55
+ kwalify (0.7.2)
56
+ maruku (0.7.3)
49
57
  memoist (0.16.2)
50
58
  mini_mime (1.0.2)
51
59
  mini_portile2 (2.4.0)
52
- multi_json (1.14.1)
60
+ multi_json (1.15.0)
53
61
  multipart-post (2.1.1)
54
- nokogiri (1.10.9)
62
+ nokogiri (1.10.10)
55
63
  mini_portile2 (~> 2.4.0)
56
- os (1.1.0)
57
- public_suffix (4.0.5)
64
+ os (1.1.1)
65
+ parallel (1.20.1)
66
+ parser (2.7.2.0)
67
+ ast (~> 2.4.1)
68
+ psych (3.2.0)
69
+ public_suffix (4.0.6)
70
+ rainbow (3.0.0)
58
71
  rake (12.3.3)
72
+ reek (6.0.2)
73
+ kwalify (~> 0.7.0)
74
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
75
+ psych (~> 3.1)
76
+ rainbow (>= 2.0, < 4.0)
77
+ regexp_parser (2.0.0)
59
78
  representable (3.0.4)
60
79
  declarative (< 0.1.0)
61
80
  declarative-option (< 0.2.0)
62
81
  uber (< 0.2.0)
63
82
  retriable (3.1.2)
83
+ reverse_markdown (2.0.0)
84
+ nokogiri
85
+ rexml (3.2.4)
64
86
  roo (2.8.3)
65
87
  nokogiri (~> 1)
66
88
  rubyzip (>= 1.3.0, < 3.0.0)
89
+ rubocop (0.93.1)
90
+ parallel (~> 1.10)
91
+ parser (>= 2.7.1.5)
92
+ rainbow (>= 2.2.2, < 4.0)
93
+ regexp_parser (>= 1.8)
94
+ rexml
95
+ rubocop-ast (>= 0.6.0)
96
+ ruby-progressbar (~> 1.7)
97
+ unicode-display_width (>= 1.4.0, < 2.0)
98
+ rubocop-ast (1.2.0)
99
+ parser (>= 2.7.1.5)
100
+ ruby-progressbar (1.10.1)
101
+ ruby2_keywords (0.0.2)
67
102
  rubyzip (2.3.0)
68
103
  signet (0.14.0)
69
104
  addressable (~> 2.3)
70
105
  faraday (>= 0.17.3, < 2.0)
71
106
  jwt (>= 1.5, < 3.0)
72
107
  multi_json (~> 1.10)
108
+ solargraph (0.39.17)
109
+ backport (~> 1.1)
110
+ benchmark
111
+ bundler (>= 1.17.2)
112
+ e2mmap
113
+ jaro_winkler (~> 1.5)
114
+ maruku (~> 0.7, >= 0.7.3)
115
+ nokogiri (~> 1.9, >= 1.9.1)
116
+ parser (~> 2.3)
117
+ reverse_markdown (>= 1.0.5, < 3)
118
+ rubocop (~> 0.52)
119
+ thor (~> 1.0)
120
+ tilt (~> 2.0)
121
+ yard (~> 0.9, >= 0.9.24)
73
122
  thor (1.0.1)
123
+ tilt (2.0.10)
74
124
  uber (0.1.0)
125
+ unicode-display_width (1.7.0)
75
126
  yard (0.9.25)
76
127
 
77
128
  PLATFORMS
@@ -81,6 +132,10 @@ DEPENDENCIES
81
132
  abank!
82
133
  bundler
83
134
  rake (~> 12.0)
135
+ reek
136
+ rubocop
137
+ solargraph
138
+ yard
84
139
 
85
140
  BUNDLED WITH
86
141
  2.1.4
@@ -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
@@ -1,40 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'abank/big'
5
- require 'abank/contrato'
6
- require 'abank/folha'
7
- require 'abank/rendas'
8
- require 'abank/version'
3
+ require('thor')
4
+ require('abank/big1')
5
+ require('abank/big2')
6
+ require('abank/big3')
7
+ require('abank/folha1')
8
+ require('abank/folha2')
9
+ require('abank/version')
9
10
 
10
11
  # @author Hernani Rodrigues Vaz
11
12
  module Abank
12
13
  DR = "/home/#{`whoami`.chomp}/Downloads"
13
-
14
- class Error < StandardError; end
14
+ BD = 'hernanilr.ab'
15
15
 
16
16
  # CLI para carregar folhas calculo comuns no bigquery
17
17
  class CLI < Thor
18
18
  desc 'tag', 'classifica movimentos'
19
19
  # classifica movimentos
20
20
  def tag
21
- Big.new.mv_classifica
21
+ Big.new(options.to_h).mv_classifica.ct_dados.re_insert
22
22
  end
23
23
 
24
24
  desc 'apagamv', 'apaga movimentos'
25
25
  option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
26
26
  # apaga movimentos
27
27
  def apagamv
28
- Big.new(k: options[:k]).mv_delete.mv_insert.re_work
29
- end
30
-
31
- desc 'criact', 'cria contrato arrendamento'
32
- option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
33
- option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
34
- option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
35
- # cria contrato arrendamento
36
- def criact
37
- 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
38
29
  end
39
30
 
40
31
  desc 'apagact', 'apaga contrato arrendamento'
@@ -42,50 +33,53 @@ module Abank
42
33
  option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
43
34
  # apaga contrato arrendamento
44
35
  def apagact
45
- 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
46
46
  end
47
47
 
48
48
  desc 'recriact', 'atualiza rendas de contrato arrendamento'
49
49
  option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
50
- option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
51
50
  option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
51
+ option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
52
52
  # atualiza rendas de contrato arrendamento
53
53
  def recriact
54
- Big.new(c: options[:c], t: options[:t]).ct_apaga
55
- 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
56
57
  end
57
58
 
58
59
  desc 'recriare', 'atualiza rendas dos contratos ativos'
59
60
  option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
60
61
  # atualiza rendas dos contratos ativos
61
62
  def recriare
62
- Big.new(t: options[:t]).re_atualiza
63
+ Big.new(options.transform_keys(&:to_sym)).re_atualiza
63
64
  end
64
65
 
65
- desc 'load', 'carrega dados da folha calculo'
66
+ desc 'work', 'carrega/apaga dados da folha calculo'
66
67
  option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
67
68
  option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
68
69
  option :v, banner: 'DATA', default: '', desc: 'data valor para movimentos a carregar'
69
- option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
70
- # carrega folha calculo
71
- def load
72
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
73
- Big::Folha.new(load_opc.merge(f: f)).processa_xls
70
+ option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
71
+ # carrega/apaga dados da folha calculo
72
+ def work
73
+ Dir.glob("#{DR}/*.xlsx").sort.each do |file|
74
+ Folha.new(options.transform_keys(&:to_sym).merge(f: file, i: true)).processa_xls
74
75
  end
75
76
  end
76
77
 
77
78
  desc 'show', 'mostra dados da folha calculo'
78
79
  # mostra folha calculo
79
80
  def show
80
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
81
- Big::Folha.new(f: f).processa_xls
82
- end
83
- end
84
-
85
- no_commands do
86
- # @return [Hash] opcoes trabalho com movimentos para load
87
- def load_opc
88
- { 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
89
83
  end
90
84
  end
91
85
 
@@ -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