You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
535 B
16 lines
535 B
1 year ago
|
module CollectionResourcesHelper
|
||
|
def file_type_size_and_pages(file, number_of_pages: nil)
|
||
|
extension_mapping = {
|
||
|
"xlsx" => "Microsoft Excel",
|
||
|
"pdf" => "PDF",
|
||
|
}
|
||
|
extension = File.extname(file)[1..]
|
||
|
|
||
|
file_type = extension_mapping.fetch(extension, extension)
|
||
|
|
||
|
file_size = number_to_human_size(File.size("public/files/#{file}"), precision: 0, significant: false)
|
||
|
file_pages = number_of_pages ? pluralize(number_of_pages, "page") : nil
|
||
|
[file_type, file_size, file_pages].compact.join(", ")
|
||
|
end
|
||
|
end
|