Class: Fedora2To3PidRenamer::Manager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Manager

Returns a new instance of Manager.



8
9
10
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 6

def config
  @config
end

Instance Method Details

#create_output_folderObject



12
13
14
15
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 12

def create_output_folder
  return false if Dir.exist?(config.output_folder)
  FileUtils.mkdir config.output_folder
end

#input_file_patternObject



31
32
33
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 31

def input_file_pattern
  File.join config.input_folder, '*'
end

#manipulator_for(file_name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 35

def manipulator_for(file_name)
  case file_name
  when /\.xml$/
    Manipulator::Xml
  when /cmodel-\d+\.deployments.txt/
    Manipulator::Text
  else
    nil
  end
end

#run_manipulationObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fedora_2_to_3_pid_renamer/manager.rb', line 17

def run_manipulation
  create_output_folder
  Dir.glob(input_file_pattern).each do |input_file|
    file_name = File.basename input_file
    manipulator = manipulator_for(file_name)
    next unless manipulator
    
    input = File.read input_file        
    output_file = File.join config.output_folder, file_name
    
    File.write output_file, manipulator.output_for(input, config)
  end
end