Module: Trashinfo

Defined in:
lib/trashinfo.rb

Class Method Summary collapse

Class Method Details

.new(path) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/trashinfo.rb', line 4

def self.new (path)
  trashinfo_string = <<~DESKTOP
    [Trash Info]
    Path=#{CGI.escape(File.expand_path path)}
    DeletionDate=#{Time.now.strftime('%Y-%m-%dT%H:%M:%S')}
  DESKTOP
end

.parse(trashinfo) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/trashinfo.rb', line 12

def self.parse (trashinfo)
  regex = /\A\[Trash Info\]\nPath=(?<path>\S+)\nDeletionDate=(?<deletion_date>\S+)/m

  matches = regex.match trashinfo

  parts = {
    :path => CGI.unescape(matches[:path]),
    :deletion_date => matches[:deletion_date]
  }
end