Class: Cliptic::Terminal::Reset_Stats

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

Class Method Summary collapse

Class Method Details

.confirm_reset(table) ⇒ Object



50
51
52
53
54
55
# File 'lib/cliptic/terminal.rb', line 50

def self.confirm_reset(table)
  puts prompt(table)
  user_confirmed? ?
    reset(table) : 
    puts("Wise choice")
end

.prompt(table) ⇒ Object



56
57
58
59
60
61
# File 'lib/cliptic/terminal.rb', line 56

def self.prompt(table)
  <<~prompt
  cliptic: Reset #{table}
  Are you sure? This cannot be undone! [Y/n]
  prompt
end

.reset(table) ⇒ Object



65
66
67
68
69
# File 'lib/cliptic/terminal.rb', line 65

def self.reset(table)
  table == "all" ?
    Database::Delete.all :
    Database::Delete.table(table)
end

.routeObject



39
40
41
42
43
44
45
# File 'lib/cliptic/terminal.rb', line 39

def self.route
  if valid_options.include?(c = ARGV.shift)
    ->{confirm_reset(c)}
  else 
    ->{puts "Unknown option #{c}"}
  end
end

.user_confirmed?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/cliptic/terminal.rb', line 62

def self.user_confirmed?
  gets.chomp === "Y"
end

.valid_optionsObject



47
48
49
# File 'lib/cliptic/terminal.rb', line 47

def self.valid_options
  ["scores", "all", "states", "recents"]
end