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

#run(options) ⇒ Object

The entry point for the application logic



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

def run(options)
  Options.iterate_on_input(options) do |o|
    if o[:directory]
      fork { run_single_image(o) }
    else
      run_single_image(o)
    end
  end
  Process.waitall
end

#run_single_image(o) ⇒ Object

rubocop:disable MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/image_svd/cli.rb', line 19

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