Class: ImageSvd::CLI

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

Overview

This class is responsible for handling the command line interface

Instance Method Summary collapse

Instance Method Details

#async_batch(arr_options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/image_svd/cli.rb', line 14

def async_batch(arr_options)
  arr_options.each do |o|
    if o[:directory]
      fork { run_single_image(o) }
    else
      run_single_image(o)
    end
  end
  Process.waitall
end

#run(options) ⇒ Object

The entry point for the application logic



7
8
9
10
11
12
# File 'lib/image_svd/cli.rb', line 7

def run(options)
  pool = Options.collect_input(options)
  until pool.empty?
    async_batch(pool.slice!(0..(options[:thread_count] - 1)))
  end
end

#run_single_image(o) ⇒ Object

rubocop:disable MethodLength



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/image_svd/cli.rb', line 26

def run_single_image(o)
  if o[:read] == true
    app = ImageSvd::ImageMatrix.new_from_svd_savefile(o)
    app.to_image(o[:output_name])
  else
    app = ImageSvd::ImageMatrix.new(o[:singular_values], o[:grayscale])
    app.read_image(o[:input_file])
    if o[:archive] == true
      app.save_svd(o[:output_name])
    elsif o[:convert] == true
      app.to_image(o[:output_name])
    end
  end
end