Class: Lipaste::Files
- Inherits:
-
Object
- Object
- Lipaste::Files
- Defined in:
- lib/lipaste/files.rb
Class Method Summary collapse
- .get_downloads_dir ⇒ Object
- .get_latest_downloaded_pgn ⇒ Object
- .get_latest_file(files) ⇒ Object
- .list_pgn_files(dir) ⇒ Object
Class Method Details
.get_downloads_dir ⇒ Object
9 10 11 12 |
# File 'lib/lipaste/files.rb', line 9 def self.get_downloads_dir home = File. "~" File.join home, "Downloads" end |
.get_latest_downloaded_pgn ⇒ Object
3 4 5 6 7 |
# File 'lib/lipaste/files.rb', line 3 def self.get_latest_downloaded_pgn downloads = get_downloads_dir pgns = list_pgn_files downloads get_latest_file pgns end |
.get_latest_file(files) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/lipaste/files.rb', line 19 def self.get_latest_file(files) mtimes = files.map {|f| {name: f, mtime: File.mtime(f)}} mtimes.sort! {|a, b| a[:mtime] - b[:mtime]} file = mtimes.pop file[:name] end |
.list_pgn_files(dir) ⇒ Object
14 15 16 17 |
# File 'lib/lipaste/files.rb', line 14 def self.list_pgn_files(dir) glob = File.join dir, "*" Dir.glob(glob).select {|f| f =~ /\.pgn$/} end |