Class: Omnizip::Commands::ParityCreateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/commands/parity_create_command.rb

Overview

Command to create PAR2 parity files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, options = {}) ⇒ ParityCreateCommand

Initialize command

Parameters:

  • files (Array<String>)

    Files or patterns to protect

  • options (Hash) (defaults to: {})

    Command options



17
18
19
20
# File 'lib/omnizip/commands/parity_create_command.rb', line 17

def initialize(files, options = {})
  @files = files
  @options = default_options.merge(options)
end

Instance Attribute Details

#filesArray<String> (readonly)

Returns Files to protect.

Returns:

  • (Array<String>)

    Files to protect



8
9
10
# File 'lib/omnizip/commands/parity_create_command.rb', line 8

def files
  @files
end

#optionsHash (readonly)

Returns Command options.

Returns:

  • (Hash)

    Command options



11
12
13
# File 'lib/omnizip/commands/parity_create_command.rb', line 11

def options
  @options
end

Instance Method Details

#runInteger

Execute command

Returns:

  • (Integer)

    Exit code (0 for success)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/omnizip/commands/parity_create_command.rb', line 25

def run
  validate_inputs!

  progress = create_progress_callback if @options[:verbose]

  created_files = []
  @files.each do |file_pattern|
    par2_files = Parity.create(
      file_pattern,
      redundancy: @options[:redundancy],
      block_size: @options[:block_size],
      output_dir: @options[:output_dir],
      progress: progress,
    )

    created_files.concat(par2_files)
  end

  report_success(created_files)
  0
rescue StandardError => e
  report_error(e)
  1
end