dir-to-xml 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -2
- data/lib/dir-to-xml.rb +47 -4
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ec027c2c2452bc9559469830c0a42382e81aedc
|
4
|
+
data.tar.gz: 6ef254eae0c663a8805337f26a6b62a75e6e76e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3649db45223135804b8a7d7c01f53b51434008203fba151f7f494f0f7656c91746f5d9ca1a023bce9160816da216c9a69a92d939ca41bb33873c92abedddd2d9
|
7
|
+
data.tar.gz: 6b7d6347aa1226ac4eb2fb4c3db93507abb9cd24e6631dded4639b12115f848b2cf2b26e5475cdbea32bdc18250053ebdb252a495c375c531ad801fc87d6c2b7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
��
|
2
|
-
��S|)���?��W"KYVU��~Q^�LsD�r�FW��)�?���"�.Ӑw�<�XP�>h!^�k5q��I#�0�lșC���W���<�f�{/I��` �E�|&H�m�"kx�"�������griu-k`9���&��@,��%N<
|
1
|
+
�.7J�{[~Cx��!�hZ�TEm����ZΫ�i�w��?IO\c��ׅj��H�k����OQ����2�� ��NG��@v��}G�VP�,�ނ {3�TK��7ʘ�y�ȩQJ3!Y�j�ڽd=����-��s$2ߦ��IE��8�0���jz����nG�rl�D5�PM��/6��B\B6NkX���;Alpf�����n�6�`$7v��W+�]��u,�.&:L��3��s9[M�m�`���9ST8��p���v�H�u
|
data/lib/dir-to-xml.rb
CHANGED
@@ -4,6 +4,48 @@
|
|
4
4
|
|
5
5
|
require 'dynarex'
|
6
6
|
|
7
|
+
class DirToXML
|
8
|
+
|
9
|
+
attr_reader :status
|
10
|
+
|
11
|
+
def initialize(path= '.')
|
12
|
+
super()
|
13
|
+
old_path = Dir.pwd
|
14
|
+
raise "Directory not found." unless File.exists? path
|
15
|
+
Dir.chdir path
|
16
|
+
|
17
|
+
a = Dir.glob("*").sort
|
18
|
+
|
19
|
+
command = a.include?('dir.xml') ? 'run' : 'new_run'
|
20
|
+
@doc, @status = self.send command, a
|
21
|
+
|
22
|
+
Dir.chdir old_path #File.expand_path('~')
|
23
|
+
@h = self.to_dynarex.to_h
|
24
|
+
@object = @h
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_by_ext(ext)
|
28
|
+
@object = @h.select{|x| x[:ext][/#{ext}/]}
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def sort_by(sym)
|
33
|
+
procs = [[:last_modified, lambda{|obj| obj\
|
34
|
+
.sort_by{|x| x[:last_modified]}}]]
|
35
|
+
proc1 = procs.assoc(sym).last
|
36
|
+
proc1.call(@object)
|
37
|
+
end
|
38
|
+
|
39
|
+
def sort_by_last_modified()
|
40
|
+
sort_by :last_modified
|
41
|
+
end
|
42
|
+
|
43
|
+
alias sort_by_lastmodified sort_by_last_modified
|
44
|
+
|
45
|
+
def to_h
|
46
|
+
@object || @h
|
47
|
+
end
|
48
|
+
|
7
49
|
class DirToXML
|
8
50
|
|
9
51
|
attr_reader :status
|
@@ -119,7 +161,7 @@ summary = "
|
|
119
161
|
doc = Rexle.new(File.open('dir.xml','r').read)
|
120
162
|
|
121
163
|
doc.root.xpath('records/file').each do |x|
|
122
|
-
x.element('last_modified').text = File.mtime x.text('name')
|
164
|
+
x.element('last_modified').text = File.mtime x.text('name') if File.exists?(x.text('name'))
|
123
165
|
end
|
124
166
|
|
125
167
|
a_dir = doc.root.xpath('records/file/name/text()').sort
|
@@ -132,15 +174,16 @@ summary = "
|
|
132
174
|
# files to add
|
133
175
|
files_to_insert = a - a_dir
|
134
176
|
add_files(doc, files_to_insert)
|
135
|
-
|
177
|
+
|
136
178
|
# files to delete
|
137
179
|
files_to_delete = a_dir - a
|
180
|
+
|
138
181
|
files_to_delete.each do |filename|
|
139
182
|
node = doc.root.element("records/file[name='#{filename}']")
|
140
183
|
node.delete
|
141
184
|
end
|
142
185
|
|
143
|
-
File.
|
186
|
+
File.write 'dir.xml', doc.xml(pretty: true)
|
144
187
|
[doc, "updated"]
|
145
188
|
end
|
146
|
-
end
|
189
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir-to-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
iqgRYucyTfq3VLTy6wrGN2HJj8unXh4JIFjyEvR3yvcCYl6IaHxuDfgoDfBI6MeQ
|
32
32
|
Em7HctRLQorltw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-04-
|
34
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: dynarex
|
metadata.gz.sig
CHANGED
Binary file
|