Class: Pandocomatic::MultipleFilesInput

Inherits:
Input
  • Object
show all
Defined in:
lib/pandocomatic/multiple_files_input.rb

Overview

A specific Input class to handle multiple input files

Instance Attribute Summary

Attributes inherited from Input

#errors

Instance Method Summary collapse

Methods inherited from Input

#absolute_path, #base, #errors?

Constructor Details

#initialize(input, config) ⇒ MultipleFilesInput

Create a new MultipleFilesInput. As a side-effect a temporary file is created as well containing the content of all the files in input.

Parameters:

  • input (String[])

    a list with input files



31
32
33
34
35
# File 'lib/pandocomatic/multiple_files_input.rb', line 31

def initialize(input, config)
  super(input)
  @config = config
  create_temp_file
end

Instance Method Details

#destroy!Object

Destroy the temporary file created for this MultipleFilesInput



53
54
55
56
57
58
# File 'lib/pandocomatic/multiple_files_input.rb', line 53

def destroy!
  return if @tmp_file.nil?

  @tmp_file.close
  @tmp_file.unlink
end

#directory?Boolean

Is this input a directory? A MultipleFilesInput cannot be a directory

Returns:

  • (Boolean)

    Boolean



48
49
50
# File 'lib/pandocomatic/multiple_files_input.rb', line 48

def directory?
  false
end

#nameObject

The name of this input

Returns:

  • String



40
41
42
# File 'lib/pandocomatic/multiple_files_input.rb', line 40

def name
  @tmp_file.path
end

#to_sObject

A string representation of this Input

Returns:

  • String



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pandocomatic/multiple_files_input.rb', line 63

def to_s
  input_string = @input_files.first
  previous_dir = File.dirname @input_files.first
  @input_files.slice(1..-1).each do |f|
    current_dir = File.dirname f
    if current_dir == previous_dir
      input_string += " + #{File.basename f}"
    else
      previous_dir = current_dir
      input_string += " + #{f}"
    end
  end

  input_string
end