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

View file

@ -12,6 +12,10 @@ module StringUtility
end end
def to_filesystems_compatible_filename(file_or_folder_name) 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 file_or_folder_name.strip
.sub(/^[.-]*/, '') .sub(/^[.-]*/, '')
.sub(/\.*$/, '') .sub(/\.*$/, '')

View file

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