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



141
142
# File 'lib/fileconv/base.rb', line 141

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)


119
120
121
# File 'lib/fileconv/base.rb', line 119

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



110
111
112
# File 'lib/fileconv/base.rb', line 110

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



95
96
# File 'lib/fileconv/base.rb', line 95

def init_acc(acc)
end

#init_convvoid

This method returns an undefined value.

Initialize the convertor



89
90
# File 'lib/fileconv/base.rb', line 89

def init_conv
end

#input_dirString

Input Directory

Returns:

  • (String)


62
63
64
# File 'lib/fileconv/base.rb', line 62

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)


69
70
71
# File 'lib/fileconv/base.rb', line 69

def input_ext
  @opts[:input_ext]
end

#input_files(files) ⇒ Array<String>

Note:

you can overwrite default input files

Input files

Parameters:

  • files (Array<string>)

    input files

Returns:

  • (Array<String>)


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

def input_files(files)
  files
end

#output_dirString

Output Directory

Returns:

  • (String)


75
76
77
# File 'lib/fileconv/base.rb', line 75

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



127
128
129
# File 'lib/fileconv/base.rb', line 127

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)


102
103
# File 'lib/fileconv/base.rb', line 102

def read_file(filename, acc)
end

#result_filenameString

File name for the result

Returns:

  • (String)

    the result file name



133
134
135
# File 'lib/fileconv/base.rb', line 133

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