xml_file_renamer 0.0.3 → 0.0.5
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 +49 -12
- data/bin/xml_file_renamer +5 -1
- data/lib/xml_file_renamer.rb +21 -18
- 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: f724bbb3af9ff3f489472a0b9da2f2f44ec6c9af
|
4
|
+
data.tar.gz: b352f5ffbfe5b67f29c757fc0aeb8b7caddb3217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a17043250b858c65951938abddfcf8491d06e05bfac64b08e74d344868ac31134bb6cf97fcafa35c7c0f4857c5cafecb270180d0c92f9717eca3f1f3d0355f6f
|
7
|
+
data.tar.gz: d7794693470cd7b6315cfacc90cbe64a9e34e19d0ff80d62d3dc6413cdf82ef4f860873e80cab9ba9e25e9b2e470012028874813ba8f9747e998ae3d6e91242f
|
data/README.md
CHANGED
@@ -15,33 +15,70 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
15
15
|
|
16
16
|
####Where `"Columbia Tower"` is a text node, that you can locate with a CSS selector:
|
17
17
|
|
18
|
-
'building Contact
|
18
|
+
'building Contact building_name'
|
19
19
|
|
20
20
|
|
21
21
|
##Solution:
|
22
22
|
|
23
|
-
###
|
23
|
+
###Install:
|
24
|
+
|
25
|
+
Install the gem from rubygems.org
|
26
|
+
|
27
|
+
$ gem install xml_file_renamer
|
28
|
+
|
29
|
+
###Run the command:
|
24
30
|
|
25
31
|
$ xml_file_renamer '<source_data>' '<css_selector>'
|
26
32
|
|
27
|
-
###
|
33
|
+
###Examples:
|
34
|
+
|
35
|
+
Copy example XML files provided by the gem:
|
36
|
+
|
37
|
+
$ cp -r `which xml_file_renamer`/../../gems/xml_file_renamer-0.0.3/example_xml_files ~/Documents/example_xml_files
|
38
|
+
|
39
|
+
Run the command on a single file:
|
40
|
+
|
41
|
+
$ xml_file_renamer \
|
42
|
+
~/Documents/example_xml_files/example_building_589989.xml \
|
43
|
+
'building Contact building_name'
|
44
|
+
|
45
|
+
Output:
|
46
|
+
|
47
|
+
**** Origin Directory: /Users/sealocal/Documents/example_xml_files
|
48
|
+
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
|
49
|
+
**** CSS selector: building Contact building_name
|
50
|
+
**** Source File: /Users/sealocal/Documents/example_xml_files/example_building_589989.xml
|
51
|
+
**** New File Name: Columbia Center
|
52
|
+
|
53
|
+
Instead of a single file, run the command on a directory:
|
28
54
|
|
29
|
-
$ xml_file_renamer
|
30
|
-
'/Users/sealocal/Documents/world_buildings/building_589989.xml' \
|
31
|
-
'building Contact alt_building_name'
|
55
|
+
$ xml_file_renamer ~/Documents/example_xml_files 'building Contact building_name'
|
32
56
|
|
33
|
-
|
57
|
+
Output:
|
34
58
|
|
35
|
-
**** Origin Directory: /Users/
|
36
|
-
**** Export Directory: /Users/
|
37
|
-
**** CSS selector: building Contact
|
59
|
+
**** Origin Directory: /Users/Home/Documents/example_xml_files
|
60
|
+
**** Export Directory: /Users/Home/Documents/example_xml_files/export_folder
|
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
|
64
|
+
**** CSS selector: building Contact building_name
|
38
65
|
**** Source File: example_building_589989.xml
|
39
|
-
**** New File Name: Columbia
|
66
|
+
**** 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
|
+
**** Source File: example_building_589990.xml
|
71
|
+
**** 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
|
+
**** Source File: example_building_589991.xml
|
76
|
+
**** New File Name: Premier on Pine
|
40
77
|
|
41
78
|
|
42
79
|
####Notes:
|
43
80
|
|
44
|
-
1. <source_data> must contain an XML tree.
|
81
|
+
1. <source_data> must contain an XML tree, with a match for your CSS selector.
|
45
82
|
|
46
83
|
2. <source_data> can have ANY file extension, as long as it HAS a file extension.
|
47
84
|
|
data/bin/xml_file_renamer
CHANGED
data/lib/xml_file_renamer.rb
CHANGED
@@ -8,15 +8,24 @@ class XMLFileRenamer
|
|
8
8
|
def initialize(source_data, css_selector)
|
9
9
|
@source_data = source_data
|
10
10
|
@css_selector = css_selector
|
11
|
-
end
|
12
11
|
|
13
|
-
def rename
|
14
12
|
set_origin_directory
|
15
|
-
print_origin_directory
|
16
13
|
set_export_directory
|
17
|
-
|
18
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_origin_directory
|
17
|
+
puts '**** Origin Directory: ' + @origin_directory
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_export_directory
|
21
|
+
puts '**** Export Directory: ' + @export_directory
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_css_selector
|
25
|
+
puts '**** CSS selector: ' + @css_selector
|
26
|
+
end
|
19
27
|
|
28
|
+
def rename
|
20
29
|
if (!File.directory? @source_data) && (File.exist? @source_data)
|
21
30
|
open_xml_file
|
22
31
|
query_xml_file
|
@@ -36,15 +45,13 @@ class XMLFileRenamer
|
|
36
45
|
|
37
46
|
private
|
38
47
|
def set_origin_directory
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
def print_origin_directory
|
43
|
-
puts '**** Origin Directory: ' + @origin_directory
|
44
|
-
end
|
48
|
+
if (!File.directory? @source_data) && (File.exist? @source_data)
|
49
|
+
@origin_directory = File.expand_path(File.dirname(@source_data))
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
52
|
+
if File.directory? @source_data
|
53
|
+
@origin_directory = @source_data
|
54
|
+
end
|
48
55
|
end
|
49
56
|
|
50
57
|
def set_export_directory
|
@@ -52,13 +59,9 @@ class XMLFileRenamer
|
|
52
59
|
@export_directory = @origin_directory + '/export_folder'
|
53
60
|
end
|
54
61
|
|
55
|
-
def print_export_directory
|
56
|
-
puts '**** Export Directory: ' + @export_directory
|
57
|
-
end
|
58
|
-
|
59
62
|
def open_xml_file
|
60
63
|
# Read in the file and get new file name:
|
61
|
-
puts '**** Source File: ' + @source_data
|
64
|
+
puts '**** Source File: ' + File.expand_path(@source_data).split('/')[-1]
|
62
65
|
@xml_document = Nokogiri::XML(open(@source_data))
|
63
66
|
end
|
64
67
|
|