Refactor StringUtility#to_filesystems_compatible_filename [SCI-2641]

This commit is contained in:
Matej Zrimšek 2018-10-11 20:26:42 +02:00
parent 1575da6edb
commit aa30cf6130
3 changed files with 13 additions and 26 deletions

View file

@ -71,12 +71,7 @@ module ReportsHelper
suffix = '.csv'
name.empty? ? 'Table' : name
end
obj_name = to_filesystems_compatible_filename(
obj_name.truncate(
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
omission: ''
)
)
obj_name = to_filesystems_compatible_filename(obj_name)
obj_name += "_Step#{parent.position + 1}#{suffix}"
obj_folder_name = 'Protocol attachments'
parent_module = if parent.protocol.present?
@ -95,29 +90,16 @@ module ReportsHelper
suffix = '.csv'
name.empty? ? 'Table' : name
end
obj_name = to_filesystems_compatible_filename(
obj_name.truncate(
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
omission: ''
)
)
obj_name = to_filesystems_compatible_filename(obj_name)
obj_name += suffix
obj_folder_name = 'Results attachments'
parent_module = parent
end
parent_module_name = to_filesystems_compatible_filename(
parent_module.name.truncate(
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
omission: ''
)
)
parent_exp_name = to_filesystems_compatible_filename(
parent_module.experiment.name.truncate(
Constants::EXPORTED_FILE_NAME_TRUNCATION_LENGTH,
omission: ''
)
)
parent_module_name =
to_filesystems_compatible_filename(parent_module.name)
parent_exp_name =
to_filesystems_compatible_filename(parent_module.experiment.name)
locals[:filename] = obj_name
locals[:path] = "#{parent_exp_name}/#{parent_module_name}/" \

View file

@ -12,6 +12,10 @@ module StringUtility
end
def to_filesystems_compatible_filename(file_or_folder_name)
file_or_folder_name = file_or_folder_name.truncate(
Constants::EXPORTED_FILENAME_TRUNCATION_LENGTH,
omission: ''
)
file_or_folder_name.strip
.sub(/^[.-]*/, '')
.sub(/\.*$/, '')

View file

@ -25,8 +25,9 @@ class Constants
DROPDOWN_TEXT_MAX_LENGTH = 15
# Max characters for filenames, after which they get truncated
FILENAME_TRUNCATION_LENGTH = 50
# Max characters for exported files' names, after which they get truncated
EXPORTED_FILE_NAME_TRUNCATION_LENGTH = 20
# Max characters for exported files' names and folders, after which they get
# truncated
EXPORTED_FILENAME_TRUNCATION_LENGTH = 20
USER_INITIALS_MAX_LENGTH = 4
# Password 'key stretching' factor