Class: Cns::Paymium
- Inherits:
-
Object
- Object
- Cns::Paymium
- Defined in:
- lib/cns/paymium.rb
Overview
classe para processar transacoes ledger do paymium
Instance Attribute Summary collapse
-
#api ⇒ Apius
readonly
API paymium.
-
#bqd ⇒ Array<Hash>
readonly
Todos os dados bigquery.
-
#ops ⇒ Thor::CoreExt::HashWithIndifferentAccess
readonly
Opcoes trabalho.
Instance Method Summary collapse
-
#exd ⇒ Hash
Dados exchange paymium - saldos & transacoes ledger.
-
#formata_ledger(hlx) ⇒ String
Texto formatado ledger.
-
#formata_saldos(bqm) ⇒ String
Texto formatado saldos.
-
#formata_uuid(uid, max) ⇒ String
Texto formatado identificacor da ledger.
-
#initialize(dad, pop) ⇒ Paymium
constructor
API paymium - obter saldos & transacoes ledger.
-
#kyl ⇒ Array<String>
Lista txid dos ledger novos.
-
#ledger ⇒ Array<Hash>
Lista ledger paymium novos.
-
#mostra_ledger ⇒ String
Texto transacoes ledger.
-
#mostra_resumo ⇒ String
Texto saldos & transacoes & ajuste dias.
-
#mostra_totais ⇒ String
Texto totais numero de transacoes.
Constructor Details
Instance Attribute Details
#api ⇒ Apius (readonly)
Returns API paymium.
10 11 12 |
# File 'lib/cns/paymium.rb', line 10 def api @api end |
#bqd ⇒ Array<Hash> (readonly)
Returns todos os dados bigquery.
12 13 14 |
# File 'lib/cns/paymium.rb', line 12 def bqd @bqd end |
#ops ⇒ Thor::CoreExt::HashWithIndifferentAccess (readonly)
Returns opcoes trabalho.
14 15 16 |
# File 'lib/cns/paymium.rb', line 14 def ops @ops end |
Instance Method Details
#exd ⇒ Hash
Returns dados exchange paymium - saldos & transacoes ledger.
47 48 49 50 51 52 |
# File 'lib/cns/paymium.rb', line 47 def exd @exd ||= { sl: api.account_fr, kl: api.ledger_fr } end |
#formata_ledger(hlx) ⇒ String
Returns texto formatado ledger.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cns/paymium.rb', line 78 def formata_ledger(hlx) format( '%<ky>-18.18s %<dt>19.19s %<ty>-17.17s %<mo>-4.4s %<vl>18.7f', ky: formata_uuid(hlx[:uuid], 18), dt: Time.at(hlx[:created_at_int]), ty: hlx[:name], mo: hlx[:currency].upcase, vl: hlx[:amount].to_d ) end |
#formata_saldos(bqm) ⇒ String
Returns texto formatado saldos.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cns/paymium.rb', line 63 def formata_saldos(bqm) vbq = bqd[:sl][bqm].to_d vkr = exd[:sl]["balance_#{bqm}".to_sym].to_d format( '%<mo>-5.5s %<kr>21.9f %<bq>21.9f %<ok>3.3s', mo: bqm.upcase, kr: vkr, bq: vbq, ok: vkr == vbq ? 'OK' : 'NOK' ) end |
#formata_uuid(uid, max) ⇒ String
Returns texto formatado identificacor da ledger.
92 93 94 95 |
# File 'lib/cns/paymium.rb', line 92 def formata_uuid(uid, max) int = Integer(max / 2) max < 7 ? 'erro' : "#{uid[0, int]}#{uid[-int..]}" end |
#kyl ⇒ Array<String>
Returns lista txid dos ledger novos.
55 56 57 58 |
# File 'lib/cns/paymium.rb', line 55 def kyl @kyl ||= exd[:kl].map { |oex| oex[:account_operations].map { |obj| obj[:uuid] } }.flatten - (ops[:t] ? [] : bqd[:nl].map { |obq| obq[:txid] }) end |
#ledger ⇒ Array<Hash>
Returns lista ledger paymium novos.
29 30 31 |
# File 'lib/cns/paymium.rb', line 29 def ledger @ledger ||= exd[:kl].map { |map| map[:account_operations].select { |obj| kyl.include?(obj[:uuid]) } }.flatten end |
#mostra_ledger ⇒ String
Returns texto transacoes ledger.
106 107 108 109 110 111 |
# File 'lib/cns/paymium.rb', line 106 def mostra_ledger return unless ops[:v] && ledger.count.positive? puts("\nledger data hora tipo moeda quantidade") ledger.sort { |ant, prx| prx[:created_at_int] <=> ant[:created_at_int] }.each { |obj| puts(formata_ledger(obj)) } end |
#mostra_resumo ⇒ String
Returns texto saldos & transacoes & ajuste dias.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cns/paymium.rb', line 34 def mostra_resumo puts("\nPAYMIUM\ntipo paymium bigquery") puts(formata_saldos(:btc)) puts(formata_saldos(:eur)) mostra_totais mostra_ledger return unless ledger.count.positive? puts("\nstring ajuste dias da ledger\n-h=#{kyl.map { |obj| "#{obj}:0" }.join(' ')}") end |
#mostra_totais ⇒ String
Returns texto totais numero de transacoes.
98 99 100 101 102 103 |
# File 'lib/cns/paymium.rb', line 98 def mostra_totais vkl = exd[:kl].map { |obj| obj[:account_operations].count }.flatten.inject(:+) vnl = bqd[:nl].count puts("LEDGER #{format('%<c>20i %<d>21i %<o>3.3s', c: vkl, d: vnl, o: vkl == vnl ? 'OK' : 'NOK')}") end |