Class: TVShowRenamer::CLI

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

Class Method Summary collapse

Class Method Details

.prompt(prompt) ⇒ Object



3
4
5
6
7
# File 'lib/tvshow_renamer/cli.rb', line 3

def self.prompt(prompt)
  print prompt
  $stdout.flush
  $stdin.gets.chomp.strip
end

.prompt_edit_value(prompt, value = nil, regex = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tvshow_renamer/cli.rb', line 9

def self.prompt_edit_value(prompt, value = nil, regex = nil)
  prompt << " (#{value})" if value
  prompt << " : "
  ok = false
  until ok
    str = self.prompt prompt
    if value && str.empty?
      ok = true
    else
      if !regex || str =~ regex
        value = str
        ok = true
      end
    end
  end
  value
end