arquivo 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/arquivo.rb +0 -2
- data/lib/arquivo/dir.rb +45 -40
- data/lib/arquivo/pdf.rb +1 -0
- data/lib/arquivo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48b00d56c13ecf2555807b41e63f2b6f07bad4477665904b32c016d16870bf59
|
4
|
+
data.tar.gz: 0db4a79a697243283a101693e8b644c7575a1148f656cf238da0c6d4ec6c7e09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d899b5e600af1f4ef19c35f0e6ef0425e6762b3482bbaa67eb5e895e971700b4ed73308f15e5a6218e08280f87c24efd7de11afdecc6abca8a220014850eb8
|
7
|
+
data.tar.gz: 21965e9af88ef6129dcdb8bfbcb7c5233f19e764aac33c760c497bd71de80eff02ae77bf7c1b1eef17cc734dfe3d096f51a9130956cca75cd5a5df858333e166
|
data/Gemfile.lock
CHANGED
data/lib/arquivo.rb
CHANGED
data/lib/arquivo/dir.rb
CHANGED
@@ -5,11 +5,12 @@ require 'googleauth'
|
|
5
5
|
require 'googleauth/stores/file_token_store'
|
6
6
|
|
7
7
|
module Arquivo
|
8
|
-
CO = '1>/dev/null 2>&1'
|
8
|
+
# CO = '1>/dev/null 2>&1'
|
9
|
+
CO = ''
|
9
10
|
|
10
11
|
# analisar/processar pasta
|
11
12
|
class C118dir < Enumerator
|
12
|
-
# @return [Enumerator] lista
|
13
|
+
# @return [Enumerator] lista items dentro duma pasta
|
13
14
|
attr_reader :items
|
14
15
|
# @return [String] documento c118
|
15
16
|
attr_reader :item
|
@@ -24,10 +25,50 @@ module Arquivo
|
|
24
25
|
@items = Dir.glob(File.join(pasta, '*')).each
|
25
26
|
@base = File.basename(pasta, File.extname(pasta)) +
|
26
27
|
Date.today.strftime('%Y%m%d')
|
27
|
-
|
28
|
+
obtem_dados(pasta)
|
29
|
+
system 'mkdir -p tmp/zip'
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
# @return [String] ficheiro dentro da pasta
|
33
|
+
def next_item
|
34
|
+
@item = items.next
|
35
|
+
rescue StopIteration
|
36
|
+
@item = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def processa_pasta(options)
|
40
|
+
n = 0
|
41
|
+
while next_item
|
42
|
+
if File.ftype(item) == 'directory'
|
43
|
+
C118dir.new(item).processa_pasta(options)
|
44
|
+
else
|
45
|
+
processa_file(options, File.extname(item).downcase)
|
46
|
+
n += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
processa_fim(n) if n.positive?
|
50
|
+
end
|
51
|
+
|
52
|
+
def processa_fim(num)
|
53
|
+
system "rm -f #{base}.*;" \
|
54
|
+
"pdftk tmp/stamped*.pdf cat output #{base}.pdf;" \
|
55
|
+
"cd tmp/zip;tar cf ../../#{base}.tar *.pdf;" \
|
56
|
+
"cd ../..;gzip --best #{base}.tar;" \
|
57
|
+
'rm -rf ./tmp'
|
58
|
+
puts "#{base} (#{num})"
|
59
|
+
end
|
60
|
+
|
61
|
+
def processa_file(options, ext)
|
62
|
+
case ext
|
63
|
+
when '.mp3' then puts item
|
64
|
+
when '.jpg' then C118jpg.new(item).processa_jpg(options, dados)
|
65
|
+
when '.pdf' then C118pdf.new(item).processa_pdf(options, dados)
|
66
|
+
else
|
67
|
+
puts "erro: #{item} so posso processar mp3, jpg, pdf"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def obtem_dados(dir)
|
31
72
|
return unless /fac?tura/i.match?(dir) ||
|
32
73
|
/recibo/i.match?(dir) ||
|
33
74
|
dados.empty?
|
@@ -70,41 +111,5 @@ module Arquivo
|
|
70
111
|
code: '<codigo-aqui>',
|
71
112
|
base_url: oob)
|
72
113
|
end
|
73
|
-
|
74
|
-
# @return [String] texto duma pagina pdf
|
75
|
-
def next_item
|
76
|
-
@item = items.next
|
77
|
-
rescue StopIteration
|
78
|
-
@item = nil
|
79
|
-
end
|
80
|
-
|
81
|
-
def processa_pasta(options)
|
82
|
-
return unless next_item
|
83
|
-
|
84
|
-
if File.ftype(item) == 'directory'
|
85
|
-
C118dir.new(item).processa_pasta(options)
|
86
|
-
else
|
87
|
-
processa_file(options)
|
88
|
-
processa_pasta(options)
|
89
|
-
processa_fim
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def processa_fim
|
94
|
-
system "rm -f #{base}.*;" \
|
95
|
-
"pdftk tmp/stamped*.pdf cat output #{base}.pdf;" \
|
96
|
-
"cd tmp/zip;tar cf ../../#{base}.tar *.pdf;" \
|
97
|
-
"gzip --best ../../#{base}.tar"
|
98
|
-
end
|
99
|
-
|
100
|
-
def processa_file(options)
|
101
|
-
case File.extname(item).downcase
|
102
|
-
when '.mp3' then puts 'mp3'
|
103
|
-
when '.jpg' then C118jpg.new(item).processa_jpg(options, dados)
|
104
|
-
when '.pdf' then C118pdf.new(item).processa_pdf(options, dados)
|
105
|
-
else
|
106
|
-
puts "erro: #{item} so posso processar mp3, jpg, pdf"
|
107
|
-
end
|
108
|
-
end
|
109
114
|
end
|
110
115
|
end
|
data/lib/arquivo/pdf.rb
CHANGED
data/lib/arquivo/version.rb
CHANGED