Class: XMLFileRenamer
- Inherits:
-
Object
- Object
- XMLFileRenamer
- Defined in:
- lib/xml_file_renamer.rb
Instance Attribute Summary collapse
-
#case_option ⇒ Object
readonly
Returns the value of attribute case_option.
-
#css_selector ⇒ Object
readonly
Returns the value of attribute css_selector.
-
#destination_file_name ⇒ Object
readonly
Returns the value of attribute destination_file_name.
-
#export_directory ⇒ Object
readonly
Returns the value of attribute export_directory.
-
#new_file_name ⇒ Object
readonly
Returns the value of attribute new_file_name.
-
#origin_directory ⇒ Object
readonly
Returns the value of attribute origin_directory.
-
#source_data ⇒ Object
readonly
Returns the value of attribute source_data.
-
#xml_document ⇒ Object
readonly
Returns the value of attribute xml_document.
Instance Method Summary collapse
-
#initialize(source_data, css_selector, case_option = nil) ⇒ XMLFileRenamer
constructor
A new instance of XMLFileRenamer.
- #print_case_option ⇒ Object
- #print_css_selector ⇒ Object
- #print_export_directory ⇒ Object
- #print_file_name ⇒ Object
- #print_origin_directory ⇒ Object
- #rename ⇒ Object
Constructor Details
#initialize(source_data, css_selector, case_option = nil) ⇒ XMLFileRenamer
9 10 11 12 13 14 15 16 |
# File 'lib/xml_file_renamer.rb', line 9 def initialize(source_data, css_selector, case_option = nil) @source_data = source_data @css_selector = css_selector @case_option = case_option set_origin_directory set_export_directory end |
Instance Attribute Details
#case_option ⇒ Object (readonly)
Returns the value of attribute case_option.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def case_option @case_option end |
#css_selector ⇒ Object (readonly)
Returns the value of attribute css_selector.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def css_selector @css_selector end |
#destination_file_name ⇒ Object (readonly)
Returns the value of attribute destination_file_name.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def destination_file_name @destination_file_name end |
#export_directory ⇒ Object (readonly)
Returns the value of attribute export_directory.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def export_directory @export_directory end |
#new_file_name ⇒ Object (readonly)
Returns the value of attribute new_file_name.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def new_file_name @new_file_name end |
#origin_directory ⇒ Object (readonly)
Returns the value of attribute origin_directory.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def origin_directory @origin_directory end |
#source_data ⇒ Object (readonly)
Returns the value of attribute source_data.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def source_data @source_data end |
#xml_document ⇒ Object (readonly)
Returns the value of attribute xml_document.
5 6 7 |
# File 'lib/xml_file_renamer.rb', line 5 def xml_document @xml_document end |
Instance Method Details
#print_case_option ⇒ Object
33 34 35 36 |
# File 'lib/xml_file_renamer.rb', line 33 def print_case_option puts '**** Case Option: ' + case_option if case_option != nil case_option end |
#print_css_selector ⇒ Object
28 29 30 31 |
# File 'lib/xml_file_renamer.rb', line 28 def print_css_selector puts '**** CSS selector: ' + css_selector css_selector end |
#print_export_directory ⇒ Object
23 24 25 26 |
# File 'lib/xml_file_renamer.rb', line 23 def print_export_directory puts '**** Export Directory: ' + export_directory export_directory end |
#print_file_name ⇒ Object
38 39 40 |
# File 'lib/xml_file_renamer.rb', line 38 def print_file_name puts '**** New File Name: ' + new_file_name end |
#print_origin_directory ⇒ Object
18 19 20 21 |
# File 'lib/xml_file_renamer.rb', line 18 def print_origin_directory puts '**** Origin Directory: ' + origin_directory origin_directory end |
#rename ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xml_file_renamer.rb', line 43 def rename new_file = if (!File.directory? source_data) && (File.exist? source_data) open_xml_file query_xml_file convert_case export_xml_file end if File.directory? source_data new_files = [] Dir.chdir(source_data) do all_regular_files_in_directory = Dir.glob('*.*') all_regular_files_in_directory.each do |file_name| xml_file_renamer = XMLFileRenamer.new(file_name, css_selector, case_option) new_files << xml_file_renamer.rename end end end new_file || new_files end |