Class: ActiveStorage::Filename
- Inherits:
-
Object
- Object
- ActiveStorage::Filename
- Includes:
- Comparable
- Defined in:
- lib/active_storage/filename.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #base ⇒ Object
- #extension ⇒ Object
- #extname ⇒ Object
-
#initialize(filename) ⇒ Filename
constructor
A new instance of Filename.
- #sanitized ⇒ Object
- #to_s ⇒ Object
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 |
#base ⇒ Object
16 17 18 |
# File 'lib/active_storage/filename.rb', line 16 def base File.basename(@filename, extname) end |
#extension ⇒ Object
12 13 14 |
# File 'lib/active_storage/filename.rb', line 12 def extension extname.from(1) end |
#extname ⇒ Object
8 9 10 |
# File 'lib/active_storage/filename.rb', line 8 def extname File.extname(@filename) end |
#sanitized ⇒ Object
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_s ⇒ Object
24 25 26 |
# File 'lib/active_storage/filename.rb', line 24 def to_s sanitized.to_s end |