class Balboa::CLI::Defaults

Constants

TOTAL_WORK_HOURS

Public Class Methods

new(cli) click to toggle source
# File lib/balboa/cli/defaults.rb, line 14
def initialize(cli)
  @config = {}
  @cli = cli
end
prompt(*args) click to toggle source
# File lib/balboa/cli/defaults.rb, line 10
def self.prompt(*args)
  new(*args).prompt
end

Public Instance Methods

prompt() click to toggle source
# File lib/balboa/cli/defaults.rb, line 19
def prompt
  prompt_attributes

  prompt_schedule

  create_file

  @config
end

Private Instance Methods

create_file() click to toggle source
# File lib/balboa/cli/defaults.rb, line 31
def create_file
  @config.reject! { |_, key| key.empty? }
  @config['skips'] = []

  File.open(Balboa::CONFIG_FILE, 'w') do |file|
    file.write(@config.to_yaml)
  end
end
prompt_attributes() click to toggle source
# File lib/balboa/cli/defaults.rb, line 40
def prompt_attributes
  @cli.say("\nFirst run. Please type your settings!")

  @config['email'] = prompt_email
  @config['password'] = prompt_password
  @config['project'] = prompt_project
end
prompt_email() click to toggle source
# File lib/balboa/cli/defaults.rb, line 48
def prompt_email
  @cli.ask('E-mail: ')
end
prompt_leave() click to toggle source
# File lib/balboa/cli/defaults.rb, line 85
def prompt_leave
  default = TOTAL_WORK_HOURS
  default -= @config['lunch_at'].to_i - @config['start_at'].to_i
  default += @config['restart_at'].to_i

  @cli.ask("\nLeave: ") { |qst| qst.default = default.to_s }
end
prompt_lunch() click to toggle source
# File lib/balboa/cli/defaults.rb, line 73
def prompt_lunch
  default = @config['start_at'].to_i + 4

  @cli.ask("\nLunch: ") { |qst| qst.default = default.to_s }
end
prompt_password() click to toggle source
# File lib/balboa/cli/defaults.rb, line 52
def prompt_password
  @cli.say("\nPassword can be stored as text or passed via option!")

  @cli.ask('Password: ') { |qst| qst.echo = '*' }
end
prompt_project() click to toggle source
# File lib/balboa/cli/defaults.rb, line 58
def prompt_project
  @cli.ask("\nProject: ")
end
prompt_restart() click to toggle source
# File lib/balboa/cli/defaults.rb, line 79
def prompt_restart
  default = @config['lunch_at'].to_i + 1

  @cli.ask("\nSecond shift: ") { |qst| qst.default = default.to_s }
end
prompt_schedule() click to toggle source
# File lib/balboa/cli/defaults.rb, line 62
def prompt_schedule
  @config['start_at'] = prompt_start
  @config['lunch_at'] = prompt_lunch
  @config['restart_at'] = prompt_restart
  @config['leave_at'] = prompt_leave
end
prompt_start() click to toggle source
# File lib/balboa/cli/defaults.rb, line 69
def prompt_start
  @cli.ask("\nFirst shift: ") { |qst| qst.default = '8' }
end