class Zaru

Defined in:

zaru.cr

Constant Summary

CHARACTER_FILTER = /[\x00-\x1F\/\\:\*\?\"<>\|]/i
FALLBACK_FILENAME = "file"
UNICODE_WHITESPACE = /[[:space:]]+/i
VERSION = "0.1.0"
WINDOWS_RESERVED_NAMES = ["CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"] of ::String

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(filename, fallback, padding) #

[View source]

Class Method Detail

def self.sanitize!(filename, fallback = nil, padding = nil) #

convenience method


[View source]

Instance Method Detail

def normalize #

strip whitespace on beginning and end collapse intra-string whitespace into single spaces


[View source]
def sanitize #

remove bad things!

  • remove characters that aren't allowed cross-OS
  • don't allow certain special filenames (issue on Windows)
  • don't allow filenames to start with a dot
  • don't allow empty filenames

this renormalizes after filtering in order to collapse whitespace


[View source]
def to_s #
Description copied from class Object

Returns a string representation of this object.

Descendants must usually not override this method. Instead, they must override to_s(io), which must append to the given IO object.


[View source]
def truncate #

cut off at 255 characters optionally provide a padding, which is useful to make sure there is room to add a file extension later


[View source]