abank 0.2.7 → 0.3.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: cc1db6b7872fbccb5da608191caea95a6c79e598b40dc86f64b4c64597a57a2a
4
- data.tar.gz: c021d951d7cfb4c83413a72c097bdf7958e75ae4c886277da3848a3e88b97242
3
+ metadata.gz: '091964a8a8df851391811bef625bf3497f51637c27d95a90951f76864d701123'
4
+ data.tar.gz: bf2e64b4a418442b4c2be60b70afc1f53d99622a2052d5d63c997e31eeccffac
5
5
  SHA512:
6
- metadata.gz: 859152f519b2517cfbbbe36635f92b66ff648e8ebf24fe9bb041d40e2d1f953094d75d94cca4f198ee90df68ad40abd9ceeb24d10b06ebafc2eb7a00ee00da69
7
- data.tar.gz: 8f2fdb535d5edd44e6c3a8a959475de72bb8760685509317a2194d6e2e4f56833ecfd0891d850ad6647c1db2fd46d7b90b405f5975a4a29a7cdc7b16eb2d12bc
6
+ metadata.gz: 1a31f93bb1e1fd498055a92900067465c522876328285305ec389cf276553068011ed51f928d35e6b8cab75291eda6011cd8e1ec9ec9a3f9da0349f078112295
7
+ data.tar.gz: 44b1a9f7f4dec92bf3fc0df88ceacdc05bd01288b4770de6532a1babe08f009f6ce0e96fb58599cab923ff5f3766fafbffdf2da0118d55429b5130981f33c1ac
@@ -1,30 +1,15 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
  EnabledByDefault: true
4
4
 
5
5
  Style/Copyright:
6
- Enabled: false
6
+ Enabled: false
7
7
 
8
- Style/DocumentationMethod:
9
- Enabled: false
10
-
11
- Style/MethodCallWithArgsParentheses:
12
- Enabled: false
8
+ Lint/ConstantResolution:
9
+ Enabled: false
13
10
 
14
11
  Style/ConstantVisibility:
15
- Enabled: false
16
-
17
- Layout/MultilineMethodArgumentLineBreaks:
18
- Enabled: false
19
-
20
- Layout/MultilineHashKeyLineBreaks:
21
- Enabled: false
22
-
23
- Layout/FirstMethodParameterLineBreak:
24
- Enabled: false
25
-
26
- Layout/FirstHashElementLineBreak:
27
- Enabled: false
12
+ Enabled: false
28
13
 
29
- Style/MissingElse:
30
- Enabled: false
14
+ Style/EmptyElse:
15
+ EnforcedStyle: nil
@@ -2,4 +2,4 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  rvm:
5
- - 2.6.3
5
+ - 2.7.0
@@ -1,43 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.7)
4
+ abank (0.3.3)
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.52.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,82 @@ 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
+ kramdown (2.3.0)
56
+ rexml
57
+ kramdown-parser-gfm (1.1.0)
58
+ kramdown (~> 2.0)
59
+ kwalify (0.7.2)
49
60
  memoist (0.16.2)
50
61
  mini_mime (1.0.2)
51
62
  mini_portile2 (2.4.0)
52
- multi_json (1.14.1)
63
+ multi_json (1.15.0)
53
64
  multipart-post (2.1.1)
54
- nokogiri (1.10.9)
65
+ nokogiri (1.10.10)
55
66
  mini_portile2 (~> 2.4.0)
56
- os (1.1.0)
57
- public_suffix (4.0.5)
67
+ os (1.1.1)
68
+ parallel (1.20.1)
69
+ parser (2.7.2.0)
70
+ ast (~> 2.4.1)
71
+ psych (3.2.1)
72
+ public_suffix (4.0.6)
73
+ rainbow (3.0.0)
58
74
  rake (12.3.3)
75
+ reek (6.0.2)
76
+ kwalify (~> 0.7.0)
77
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
78
+ psych (~> 3.1)
79
+ rainbow (>= 2.0, < 4.0)
80
+ regexp_parser (2.0.1)
59
81
  representable (3.0.4)
60
82
  declarative (< 0.1.0)
61
83
  declarative-option (< 0.2.0)
62
84
  uber (< 0.2.0)
63
85
  retriable (3.1.2)
86
+ reverse_markdown (2.0.0)
87
+ nokogiri
88
+ rexml (3.2.4)
64
89
  roo (2.8.3)
65
90
  nokogiri (~> 1)
66
91
  rubyzip (>= 1.3.0, < 3.0.0)
92
+ rubocop (1.6.1)
93
+ parallel (~> 1.10)
94
+ parser (>= 2.7.1.5)
95
+ rainbow (>= 2.2.2, < 4.0)
96
+ regexp_parser (>= 1.8, < 3.0)
97
+ rexml
98
+ rubocop-ast (>= 1.2.0, < 2.0)
99
+ ruby-progressbar (~> 1.7)
100
+ unicode-display_width (>= 1.4.0, < 2.0)
101
+ rubocop-ast (1.3.0)
102
+ parser (>= 2.7.1.5)
103
+ ruby-progressbar (1.10.1)
104
+ ruby2_keywords (0.0.2)
67
105
  rubyzip (2.3.0)
68
106
  signet (0.14.0)
69
107
  addressable (~> 2.3)
70
108
  faraday (>= 0.17.3, < 2.0)
71
109
  jwt (>= 1.5, < 3.0)
72
110
  multi_json (~> 1.10)
111
+ solargraph (0.40.0)
112
+ backport (~> 1.1)
113
+ benchmark
114
+ bundler (>= 1.17.2)
115
+ e2mmap
116
+ jaro_winkler (~> 1.5)
117
+ kramdown (~> 2.3)
118
+ kramdown-parser-gfm (~> 1.1)
119
+ parser (~> 2.3)
120
+ reverse_markdown (>= 1.0.5, < 3)
121
+ rubocop (>= 0.52)
122
+ thor (~> 1.0)
123
+ tilt (~> 2.0)
124
+ yard (~> 0.9, >= 0.9.24)
73
125
  thor (1.0.1)
126
+ tilt (2.0.10)
74
127
  uber (0.1.0)
128
+ unicode-display_width (1.7.0)
75
129
  yard (0.9.25)
76
130
 
77
131
  PLATFORMS
@@ -81,6 +135,10 @@ DEPENDENCIES
81
135
  abank!
82
136
  bundler
83
137
  rake (~> 12.0)
138
+ reek
139
+ rubocop
140
+ solargraph
141
+ yard
84
142
 
85
143
  BUNDLED WITH
86
144
  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/rendas'
7
- require 'abank/folha'
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
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
+ option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
70
71
  # carrega/apaga dados da folha calculo
71
72
  def work
72
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
73
- 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
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
- Folha.new(f: f).processa_xls
82
- end
83
- end
84
-
85
- no_commands do
86
- # @return [Hash] opcoes trabalho com movimentos para work
87
- def work_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