Module: Fileconv::Convertor

Included in:
Base
Defined in:
lib/fileconv/base.rb

Instance Method Summary collapse

Instance Method Details

#conv_resultString?

Note:

output the string result to a file(#result_filename) and don’t create file if this method return nil(default)

Note:

you can create result data using @meta or anather instance variable you create

Conversion result

Returns:

  • (String, nil)

    the result



130
131
# File 'lib/fileconv/base.rb', line 130

def conv_result
end

#convert_file(file, acc) ⇒ String?

Note:

output the string to a file(#output_filename) and don’t create file if this method return nil

Convert a File

Parameters:

  • file (Object)

    the file object

  • acc (Hash)

    the accumulator for this file

Returns:

  • (String, nil)


108
109
110
# File 'lib/fileconv/base.rb', line 108

def convert_file(file, acc)
  file
end

#convert_line(line, acc) ⇒ Object, ...

Note:

add the line object add all lines if this method return Array and don’t add it if this method return nil

Convert a Line

Parameters:

  • line (Object)

    the line object

  • acc (Hash)

    the accumulator for this file

Returns:

  • (Object, Array, nil)

    the converted line



99
100
101
# File 'lib/fileconv/base.rb', line 99

def convert_line(line, acc)
  line
end

#init_acc(acc) ⇒ void

This method returns an undefined value.

Init a accumlator

Parameters:

  • acc (Hash)

    the accumulator for this file



84
85
# File 'lib/fileconv/base.rb', line 84

def init_acc(acc)
end

#init_convvoid

This method returns an undefined value.

Initialize the convertor



78
79
# File 'lib/fileconv/base.rb', line 78

def init_conv
end

#input_dirString

Input Directory

Returns:

  • (String)


52
53
54
# File 'lib/fileconv/base.rb', line 52

def input_dir
  @opts[:input_dir] || "."
end

#input_extString?

Note:

target all files if this method return nil

File extention for input file

Returns:

  • (String, nil)


59
60
61
# File 'lib/fileconv/base.rb', line 59

def input_ext
  @opts[:input_ext]
end

#input_filesArray<String>?

Note:

ignore #input_dir if this method return non-nil

Note:

select files by #input_dir and #input_ext if this method return nil

Input files

Returns:

  • (Array<String>, nil)


73
74
# File 'lib/fileconv/base.rb', line 73

def input_files
end

#output_dirString

Output Directory

Returns:

  • (String)


65
66
67
# File 'lib/fileconv/base.rb', line 65

def output_dir
  @opts[:output_dir] || "output"
end

#output_filename(filename, acc) ⇒ String

File name for the output

Parameters:

  • filename (String)

    original base file name

  • acc (Hash)

    the accumulator for this file

Returns:

  • (String)

    the output file name



116
117
118
# File 'lib/fileconv/base.rb', line 116

def output_filename(filename, acc)
  filename
end

#read_file(filename, acc) ⇒ Object?

Note:

use default reader if this method return nil

Read a file

Parameters:

  • acc (Hash)

    the accumulator for this file

Returns:

  • (Object, nil)


91
92
# File 'lib/fileconv/base.rb', line 91

def read_file(filename, acc)
end

#result_filenameString

File name for the result

Returns:

  • (String)

    the result file name



122
123
124
# File 'lib/fileconv/base.rb', line 122

def result_filename
  @opts[:result_file] || "result.txt"
end