Module: Executable

Included in:
ChangeMachine
Defined in:
lib/coinstar/executable.rb

Instance Method Summary collapse

Instance Method Details

#clean_input(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coinstar/executable.rb', line 7

def clean_input(args)
  arg, params = args.group_by { |a| a.include? '--' }.values

  begin
    arg = arg.first.gsub('--', '').to_sym
  rescue NoMethodError
    raise 'Please enter either --make_change or --make_cents'
  end
  begin
    params = params.first.to_i if arg == :make_change
    params = params_to_hash(params) if arg == :make_cents
  rescue NoMethodError
    raise 'Please enter the change amount' if arg == :make_change
    raise 'Please enter the cents as quarters=25 format' if arg == :make_cents
  end

  {argument: arg, params: params}
end

#run(args) ⇒ Object



2
3
4
5
# File 'lib/coinstar/executable.rb', line 2

def run(args)
  result = self.send(args[:argument], args[:params]) if self.respond_to? args[:argument]
  display(result)
end