1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/active_storage/filename.rb
David Heinemeier Hansson c624df326a ActiveVault -> ActiveStorage
Yaroslav agreed to hand over the gem name ❤️
2017-07-06 11:33:29 +02:00

31 lines
518 B
Ruby
Raw Blame History

class ActiveStorage::Filename
include Comparable
def initialize(filename)
@filename = filename
end
def extname
File.extname(@filename)
end
def extension
extname.from(1)
end
def base
File.basename(@filename, extname)
end
def sanitized
@filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "<EFBFBD>").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
end
def to_s
sanitized.to_s
end
def <=>(other)
to_s.downcase <=> other.to_s.downcase
end
end