xml_file_renamer 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ad91f071b707ca3c260b85e3dbcdb3ce3505e2c
4
- data.tar.gz: f91b487140897229a49efd79ec11348dc10a1418
3
+ metadata.gz: f724bbb3af9ff3f489472a0b9da2f2f44ec6c9af
4
+ data.tar.gz: b352f5ffbfe5b67f29c757fc0aeb8b7caddb3217
5
5
  SHA512:
6
- metadata.gz: 14a63693f183de463245d771f776a870b4210e90391a6548f82e2b373d6c888315d4dd75a81eb6de6ed9467d5b13ee0de14347099ab1add0e91490bb24ee4ce8
7
- data.tar.gz: ee2fbee0e7e7ef82a23db794b237f7e72bf5e986f760554ce4dcbe51f85f59ca3b342fd1dec0613061f7a202cd9d2d34639dc4034158c8e4a9ea7302dd3c0953
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 alt_building_name'
18
+ 'building Contact building_name'
19
19
 
20
20
 
21
21
  ##Solution:
22
22
 
23
- ###Run the script:
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
- ###Example:
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
- ###Output:
57
+ Output:
34
58
 
35
- **** Origin Directory: /Users/sealocal/Documents/world_buildings
36
- **** Export Directory: /Users/sealocal/Documents/world_buildings/export_folder
37
- **** CSS selector: building Contact alt_building_name
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 Tower
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
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'xml_file_renamer'
4
- XMLFileRenamer.new(ARGV[0], ARGV[1]).rename
4
+ xfr = XMLFileRenamer.new(ARGV[0], ARGV[1])
5
+ xfr.print_origin_directory
6
+ xfr.print_export_directory
7
+ xfr.print_css_selector
8
+ xfr.rename
@@ -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
- print_export_directory
18
- print_css_selector
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
- @origin_directory = Dir.pwd
40
- end
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
- def print_css_selector
47
- puts '**** CSS selector: ' + @css_selector
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml_file_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Taylor