Module: MaxAmount::Cli

Extended by:
Options
Defined in:
lib/max_amount/cli.rb

Class Method Summary collapse

Methods included from Options

ask

Class Method Details

.call(user_string:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/max_amount/cli.rb', line 7

def self.call(user_string:)
  options = MaxAmount::Options.ask

  case options[:m]
  when '1'
    # str = File.read File.expand_path('../test/test_data.txt', __dir__).sub('/lib', '')
    str = File.read File.expand_path('test_data.txt', __dir__)
  when '2'
    str = SecureRandom.hex(options[:l].to_i)
  when '3'
    str = user_string
  end

  params = {
    text: str,
    nmax: options[:n]&.to_i
  }

  params[:text] = params[:text].to_s.chomp unless params[:text].is_a?(String)

  begin
    output = MaxAmount::Seeker.new(params).check_errors.search.join("\n")
    puts output
  rescue MaxAmount::Error => e
    message = e.message
    puts message
  end
end