xml_file_renamer 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -7
- data/bin/xml_file_renamer +1 -1
- data/example_xml_files/example_building_589991.xml +1 -1
- data/lib/xml_file_renamer.rb +11 -9
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b95c3a28d32904fbd55a1340b978bec5eca03d0
|
4
|
+
data.tar.gz: c03e4c4b681b777fbe1592892d4b28a0271e3c00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e34f2046765834dd8c27bf9a14a50a8dcc6cf3f9022a3cd886a4977008425383b4fab20157411145634deb0e04fe3b15cd0201a6476c38d0746eb48510bdfa8b
|
7
|
+
data.tar.gz: 0c847ff691649b7332e9c0b309ef19caac70be7faefaf1121728b800dbf2ed05129c8554973654bad7528b4fa4b249bc712ebcf5cc0d15abb0c0c3267d1a834a
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
13
13
|
|
14
14
|
Columbia Tower.xml, Space Needle.xml, Premiere on Pine.xml
|
15
15
|
|
16
|
-
####Where `"Columbia Tower"` is a text node, that you can locate
|
16
|
+
####Where `"Columbia Tower"` is a text node, that you can locate by traversing tag names:
|
17
17
|
|
18
18
|
'building Contact building_name'
|
19
19
|
|
@@ -28,13 +28,13 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
28
28
|
|
29
29
|
###Run the command:
|
30
30
|
|
31
|
-
|
31
|
+
$ xml_file_renamer '<source_data>' '<tag_names>' [<case>]
|
32
32
|
|
33
33
|
###Examples:
|
34
34
|
|
35
35
|
Copy example XML files provided by the gem:
|
36
36
|
|
37
|
-
$ cp -r `which xml_file_renamer`/../../gems/xml_file_renamer-0.0.
|
37
|
+
$ cp -r `which xml_file_renamer`/../../gems/xml_file_renamer-0.0.8/example_xml_files ~/Documents/example_xml_files
|
38
38
|
|
39
39
|
Run the command on a single file:
|
40
40
|
|
@@ -46,7 +46,7 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
46
46
|
|
47
47
|
**** Origin Directory: /Users/sealocal/Documents/example_xml_files
|
48
48
|
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
|
49
|
-
****
|
49
|
+
**** Tag Names: building Contact building_name
|
50
50
|
**** Source File: example_building_589989.xml
|
51
51
|
**** New File Name: Columbia Center
|
52
52
|
|
@@ -58,18 +58,32 @@ This is a Ruby class that allows you to rename your XML files based on content i
|
|
58
58
|
|
59
59
|
**** Origin Directory: /Users/sealocal/Documents/example_xml_files
|
60
60
|
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
|
61
|
-
****
|
61
|
+
**** Tag Names: building Contact building_name
|
62
62
|
**** Source File: example_building_589989.xml
|
63
63
|
**** New File Name: Columbia Center
|
64
64
|
**** Source File: example_building_589990.xml
|
65
65
|
**** New File Name: Space Needle
|
66
66
|
**** Source File: example_building_589991.xml
|
67
|
-
**** New File Name:
|
67
|
+
**** New File Name: Premiere on Pine
|
68
68
|
|
69
69
|
|
70
|
+
Case Option:
|
71
|
+
|
72
|
+
Case options will convert the case of the new string:
|
73
|
+
|
74
|
+
$ xml_file_renamer building.xml 'building Contact building_name' lower_case
|
75
|
+
|
76
|
+
These are valid options:
|
77
|
+
|
78
|
+
lower_case #=> 'space needle.xml'
|
79
|
+
upper_case #=> 'SPACE NEEDLE.xml'
|
80
|
+
title_case #=> 'Space Needle.xml'
|
81
|
+
camel_case #=> 'SpaceNeedle.xml'
|
82
|
+
snake_case #=> 'space_needle.xml'
|
83
|
+
|
70
84
|
####Notes:
|
71
85
|
|
72
|
-
1. <source_data> must contain an XML tree, with a match for your
|
86
|
+
1. <source_data> must contain an XML tree, with a match for your tag names.
|
73
87
|
|
74
88
|
2. <source_data> can have ANY file extension. As long as it HAS a file extension,
|
75
89
|
this utility will find your file an rename it.
|
data/bin/xml_file_renamer
CHANGED
data/lib/xml_file_renamer.rb
CHANGED
@@ -2,13 +2,13 @@ require 'nokogiri'
|
|
2
2
|
require 'active_support/all'
|
3
3
|
|
4
4
|
class XMLFileRenamer
|
5
|
-
attr_reader :source_data, :
|
5
|
+
attr_reader :source_data, :tag_names, :case_option,
|
6
6
|
:xml_document, :origin_directory, :export_directory,
|
7
7
|
:new_file_name, :destination_file_name
|
8
8
|
|
9
|
-
def initialize(source_data,
|
9
|
+
def initialize(source_data, tag_names, case_option = nil)
|
10
10
|
@source_data = source_data
|
11
|
-
@
|
11
|
+
@tag_names = tag_names
|
12
12
|
@case_option = case_option
|
13
13
|
|
14
14
|
set_origin_directory
|
@@ -25,9 +25,9 @@ class XMLFileRenamer
|
|
25
25
|
export_directory
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
puts '****
|
30
|
-
|
28
|
+
def print_tag_names
|
29
|
+
puts '**** Tag Names: ' + tag_names
|
30
|
+
tag_names
|
31
31
|
end
|
32
32
|
|
33
33
|
def print_case_option
|
@@ -53,7 +53,7 @@ class XMLFileRenamer
|
|
53
53
|
Dir.chdir(source_data) do
|
54
54
|
all_regular_files_in_directory = Dir.glob('*.*')
|
55
55
|
all_regular_files_in_directory.each do |file_name|
|
56
|
-
xml_file_renamer = XMLFileRenamer.new(file_name,
|
56
|
+
xml_file_renamer = XMLFileRenamer.new(file_name, tag_names, case_option)
|
57
57
|
new_files << xml_file_renamer.rename
|
58
58
|
end
|
59
59
|
end
|
@@ -85,8 +85,8 @@ class XMLFileRenamer
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def query_xml_file
|
88
|
-
|
89
|
-
@new_file_name =
|
88
|
+
xml_query_by_tag_names = xml_document.css(tag_names)
|
89
|
+
@new_file_name = xml_query_by_tag_names.text.strip
|
90
90
|
end
|
91
91
|
|
92
92
|
def convert_case
|
@@ -100,6 +100,8 @@ class XMLFileRenamer
|
|
100
100
|
@new_file_name.split.join.camelcase
|
101
101
|
elsif case_option == 'snake_case'
|
102
102
|
@new_file_name.titleize.split.join.underscore
|
103
|
+
else
|
104
|
+
@new_file_name
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_file_renamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,7 +24,8 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.6.1
|
27
|
-
description: A
|
27
|
+
description: A command line executable for renaming XML files to content of an XML
|
28
|
+
tag.
|
28
29
|
email: local.mat@gmail.com
|
29
30
|
executables:
|
30
31
|
- xml_file_renamer
|
@@ -58,9 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
59
|
version: '0'
|
59
60
|
requirements: []
|
60
61
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.2.
|
62
|
+
rubygems_version: 2.2.2
|
62
63
|
signing_key:
|
63
64
|
specification_version: 4
|
64
|
-
summary:
|
65
|
+
summary: Batch rename XML files - rule the world!
|
65
66
|
test_files: []
|
66
|
-
has_rdoc:
|