Class: ActiveStorage::Filename

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/active_storage/filename.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Filename

Returns a new instance of Filename.



4
5
6
# File 'lib/active_storage/filename.rb', line 4

def initialize(filename)
  @filename = filename
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/active_storage/filename.rb', line 28

def <=>(other)
  to_s.downcase <=> other.to_s.downcase
end

#baseObject



16
17
18
# File 'lib/active_storage/filename.rb', line 16

def base
  File.basename(@filename, extname)
end

#extensionObject



12
13
14
# File 'lib/active_storage/filename.rb', line 12

def extension
  extname.from(1)
end

#extnameObject



8
9
10
# File 'lib/active_storage/filename.rb', line 8

def extname
  File.extname(@filename)
end

#sanitizedObject



20
21
22
# File 'lib/active_storage/filename.rb', line 20

def sanitized
  @filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-")
end

#to_sObject



24
25
26
# File 'lib/active_storage/filename.rb', line 24

def to_s
  sanitized.to_s
end