Class: XMLFileRenamer

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_file_renamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_optionObject (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_selectorObject (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_nameObject (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_directoryObject (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_nameObject (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_directoryObject (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_dataObject (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_documentObject (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



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


28
29
30
31
# File 'lib/xml_file_renamer.rb', line 28

def print_css_selector
  puts '**** CSS selector: ' + css_selector
  css_selector
end


23
24
25
26
# File 'lib/xml_file_renamer.rb', line 23

def print_export_directory
  puts '**** Export Directory: ' + export_directory
  export_directory
end


38
39
40
# File 'lib/xml_file_renamer.rb', line 38

def print_file_name
  puts '**** New File Name: ' + new_file_name
end


18
19
20
21
# File 'lib/xml_file_renamer.rb', line 18

def print_origin_directory
  puts '**** Origin Directory: ' + origin_directory
  origin_directory
end

#renameObject



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