Class: Fedora2To3PidRenamer::Manager
- Inherits:
-
Object
- Object
- Fedora2To3PidRenamer::Manager
- Defined in:
- lib/fedora_2_to_3_pid_renamer/manager.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #create_output_folder ⇒ Object
-
#initialize(config) ⇒ Manager
constructor
A new instance of Manager.
- #input_file_pattern ⇒ Object
- #manipulator_for(file_name) ⇒ Object
- #run_manipulation ⇒ Object
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
#config ⇒ Object
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_folder ⇒ Object
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_pattern ⇒ Object
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_manipulation ⇒ Object
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 |