lib/saved_assets.rb in markdown_exec-1.8.6 vs lib/saved_assets.rb in markdown_exec-1.8.7
- old
+ new
@@ -10,22 +10,24 @@
# given parameters. The `script_name` method derives a name for a script
# based on filename, prefix, time, and blockname. Similarly, the `stdout_name`
# method derives a name for stdout redirection.
#
class SavedAsset
- FNR11 = /pattern1/.freeze # TODO: Replace with actual pattern
- FNR12 = 'replacement_string' # TODO: Replace with actual replacement string
+ FNR11 = %r{/|:}.freeze
+ FNR12 = '_'
+ DEFAULT_FTIME = '%F-%H-%M-%S'
# Generates a formatted script name based on the provided parameters.
- def self.script_name(filename:, prefix:, time:, blockname:)
- fne = filename.gsub(FNR11, FNR12)
- "#{[prefix, time.strftime('%F-%H-%M-%S'), fne, ',', blockname].join('_')}.sh"
+ def self.script_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.sh')
+ fne = filename.gsub(pattern, replace)
+ "#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
end
# Generates a formatted stdout name based on the provided parameters.
- def self.stdout_name(filename:, prefix:, time:, blockname:)
- "#{[prefix, time.strftime('%F-%H-%M-%S'), filename, blockname].join('_')}.out.txt"
+ def self.stdout_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.out.txt')
+ fne = filename.gsub(pattern, replace)
+ "#{[prefix, time.strftime(ftime), fne, ',', blockname].join(join_str)}#{exts}"
end
end
end
if $PROGRAM_NAME == __FILE__
@@ -48,10 +50,10 @@
filename = 'sample.txt'
prefix = 'test'
time = Time.new(2023, 1, 1, 12, 0, 0)
blockname = 'block1'
- expected_name = 'test_2023-01-01-12-00-00_sample.txt_block1.out.txt'
+ expected_name = 'test_2023-01-01-12-00-00_sample.txt_,_block1.out.txt'
assert_equal expected_name,
MarkdownExec::SavedAsset.stdout_name(filename: filename, prefix: prefix, time: time,
blockname: blockname)
end
end