Class: MarkdownExec::FileInMenu

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_exec.rb

Class Method Summary collapse

Class Method Details

.for_menu(filename) ⇒ String

Prepends the age of the file in days to the file name for display in a menu.

Parameters:

  • filename (String)

    the name of the file

Returns:

  • (String)

    modified file name with age prepended



111
112
113
114
115
116
# File 'lib/markdown_exec.rb', line 111

def self.for_menu(filename)
  file_age = (Time.now - File.mtime(filename)) / (60 * 60 * 24 * 30)
  filename = ColorScheme.colorize_path(filename)

  "  #{Histogram.display(file_age, 0, 11, 12, inverse: false)}: #{filename}"
end

.from_menu(dname) ⇒ String

Removes the age from the string to retrieve the original file name.

Parameters:

  • filename_with_age (String)

    the modified file name with age

Returns:

  • (String)

    the original file name



121
122
123
124
# File 'lib/markdown_exec.rb', line 121

def self.from_menu(dname)
  filename_with_age = dname.gsub(/\033\[[\d;]+m|\033\[0m/, '')
  filename_with_age.split(': ', 2).last
end