lib/regexp_replacer.rb in markdown_exec-1.8.6 vs lib/regexp_replacer.rb in markdown_exec-1.8.7
- old
+ new
@@ -13,46 +13,46 @@
# Perform the replacement based on the specified option
def perform_replacement(option)
content = File.read(@file_path)
modified_content = case option
- when 1
- replace_pattern1(content)
- when 2
- replace_pattern2(content)
+ when 'v'
+ verbose(content)
+ when 'q'
+ quiet(content)
else
- raise "Invalid option. Please choose 1 or 2."
+ raise "Invalid option. Please choose 'v' or 'q'."
end
File.write(@file_path, modified_content)
end
private
- # Replacement for pattern 1
- def replace_pattern1(content)
- regexp = /^( *)# (@\w+) ('.+)/
- substitution = '\1;;pp __LINE__,\3 #\2'
+ # Replacement for pattern 'v'
+ def verbose(content)
+ regexp = /^( *)# (&\w+) ('.+)/
+ substitution = '\1;;pp [__LINE__,\3] #\2'
content.gsub(regexp, substitution)
end
- # Replacement for pattern 2
- def replace_pattern2(content)
- regexp = /^( *);;pp __LINE__,(.+) #(@\w+)/
+ # Replacement for pattern 'q'
+ def quiet(content)
+ regexp = /^( *);; ?pp \[__LINE__,(.+)\] #(&\w+)/
substitution = '\1# \3 \2'
content.gsub(regexp, substitution)
end
end
# Running the script with command line arguments
if ARGV.length != 2
- puts "Usage: ruby regexp_replacer.rb [file_path] [option (1 or 2)]"
+ puts "Usage: ruby regexp_replacer.rb [file_path] [option ('v' or 'q')]"
exit
end
file_path, option = ARGV
replacer = RegexpReplacer.new(file_path)
begin
- replacer.perform_replacement(option.to_i)
+ replacer.perform_replacement(option)
puts "Replacement performed successfully."
rescue StandardError => e
puts "Error: #{e.message}"
end