Class: RFactor::CLI

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

Class Method Summary collapse

Class Method Details

.startObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/r_factor/cli.rb', line 3

def self.start
  inputs = ARGV

  if inputs.empty?
    $stdin.each_line do |line|
      inputs.concat(line.split)
    end
  end

  inputs.keep_if do |arg|
    if arg.to_i.to_s == arg
      true
    else
      $stderr.puts "factor: '#{arg.gsub('\\') { '\\\\' }.gsub("'") { "\\'" }}' is not a valid positive integer"
      false
    end
  end

  inputs.each do |arg|
    factors = Factor.get_factors(arg.to_i)
    puts "#{arg}: #{factors.join(' ')}"
  end
end