xml_file_renamer 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +8 -14
- data/lib/xml_file_renamer.rb +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0688f2e5897b6dc5e2934e9946f9c432a105f3fb
|
4
|
+
data.tar.gz: 291f3d7d0f61cc74a878e156a2ebe7840d6ef157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7506fe53bc49fc86b1ad01f2890d1fa134c401f726ec6de1f53ae0205eb2084d5a028103754f1a67a97d3864de2dfa9b6deb51ab6a6b089ca877a75076343f07
|
7
|
+
data.tar.gz: 047b0c9190846a3505a3bd30e2981d2d466c7bf8331483c8df93433ea52bfc051b0a8afb181e23896586635a7e27d94864c95f011da2ed032d28d3f73137e55c
|
data/README.md
CHANGED
@@ -47,31 +47,22 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
47
47
|
**** Origin Directory: /Users/sealocal/Documents/example_xml_files
|
48
48
|
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
|
49
49
|
**** CSS selector: building Contact building_name
|
50
|
-
**** Source File:
|
50
|
+
**** Source File: example_building_589989.xml
|
51
51
|
**** New File Name: Columbia Center
|
52
52
|
|
53
|
-
Instead of a single file, run the command on a directory:
|
53
|
+
Instead of a single file, run the command on a directory (non-recursive):
|
54
54
|
|
55
55
|
$ xml_file_renamer ~/Documents/example_xml_files 'building Contact building_name'
|
56
56
|
|
57
57
|
Output:
|
58
58
|
|
59
|
-
**** Origin Directory: /Users/
|
60
|
-
**** Export Directory: /Users/
|
61
|
-
**** CSS selector: building Contact building_name
|
62
|
-
**** Origin Directory: /Users/Home/Documents/example_xml_files
|
63
|
-
**** Export Directory: /Users/Home/Documents/example_xml_files/export_folder
|
59
|
+
**** Origin Directory: /Users/sealocal/Documents/example_xml_files
|
60
|
+
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
|
64
61
|
**** CSS selector: building Contact building_name
|
65
62
|
**** Source File: example_building_589989.xml
|
66
63
|
**** New File Name: Columbia Center
|
67
|
-
**** Origin Directory: /Users/Home/Documents/example_xml_files
|
68
|
-
**** Export Directory: /Users/Home/Documents/example_xml_files/export_folder
|
69
|
-
**** CSS selector: building Contact building_name
|
70
64
|
**** Source File: example_building_589990.xml
|
71
65
|
**** New File Name: Space Needle
|
72
|
-
**** Origin Directory: /Users/Home/Documents/example_xml_files
|
73
|
-
**** Export Directory: /Users/Home/Documents/example_xml_files/export_folder
|
74
|
-
**** CSS selector: building Contact building_name
|
75
66
|
**** Source File: example_building_589991.xml
|
76
67
|
**** New File Name: Premier on Pine
|
77
68
|
|
@@ -80,12 +71,15 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
80
71
|
|
81
72
|
1. <source_data> must contain an XML tree, with a match for your CSS selector.
|
82
73
|
|
83
|
-
2. <source_data> can have ANY file extension
|
74
|
+
2. <source_data> can have ANY file extension. As long as it HAS a file extension,
|
75
|
+
this utility will find your file an rename it.
|
84
76
|
|
85
77
|
3. <source_data> can be a relative or absolute path to an XML file.
|
86
78
|
|
87
79
|
4. The output will be saved to an `export_folder`, until this project is otherwise updated.
|
88
80
|
|
81
|
+
5. The utility does not recursively find files in sub-directories. When given
|
82
|
+
a directory, only files in that directory will be processed.
|
89
83
|
|
90
84
|
##Contribute:
|
91
85
|
Please STAR, [FORK](https://github.com/sealocal/xml_file_renamer/fork), or create a new [ISSUE](https://github.com/sealocal/xml_file_renamer/issues/new) if you would like to see this project developed further. We can even rename the project when appropriate!
|
data/lib/xml_file_renamer.rb
CHANGED
@@ -15,32 +15,38 @@ class XMLFileRenamer
|
|
15
15
|
|
16
16
|
def print_origin_directory
|
17
17
|
puts '**** Origin Directory: ' + @origin_directory
|
18
|
+
@origin_directory
|
18
19
|
end
|
19
20
|
|
20
21
|
def print_export_directory
|
21
22
|
puts '**** Export Directory: ' + @export_directory
|
23
|
+
@export_directory
|
22
24
|
end
|
23
25
|
|
24
26
|
def print_css_selector
|
25
27
|
puts '**** CSS selector: ' + @css_selector
|
28
|
+
@css_selector
|
26
29
|
end
|
27
30
|
|
28
31
|
def rename
|
29
|
-
if (!File.directory? @source_data) && (File.exist? @source_data)
|
32
|
+
new_file = if (!File.directory? @source_data) && (File.exist? @source_data)
|
30
33
|
open_xml_file
|
31
34
|
query_xml_file
|
32
35
|
export_xml_file
|
33
36
|
end
|
34
37
|
|
35
38
|
if File.directory? @source_data
|
39
|
+
new_files = []
|
36
40
|
Dir.chdir(@source_data) do
|
37
41
|
all_regular_files_in_directory = Dir.glob('*.*')
|
38
42
|
all_regular_files_in_directory.each do |file_name|
|
39
43
|
xml_file_renamer = XMLFileRenamer.new(file_name, @css_selector)
|
40
|
-
xml_file_renamer.rename
|
44
|
+
new_files << xml_file_renamer.rename
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
48
|
+
|
49
|
+
new_file || new_files
|
44
50
|
end
|
45
51
|
|
46
52
|
private
|
@@ -78,6 +84,7 @@ class XMLFileRenamer
|
|
78
84
|
|
79
85
|
FileUtils.mkdir_p @export_directory
|
80
86
|
FileUtils.copy_file(@source_data, @destination_file_name)
|
87
|
+
@new_file_name
|
81
88
|
end
|
82
89
|
end
|
83
90
|
|