Class: Tahweel::Writers::Txt

Inherits:
Object
  • Object
show all
Defined in:
lib/tahweel/writers/txt.rb

Overview

Writer class for outputting text to a .txt file.

Constant Summary collapse

PAGE_SEPARATOR =
"\n\nPAGE_SEPARATOR\n\n"

Instance Method Summary collapse

Instance Method Details

#extensionString

Returns the file extension for this writer.

Returns:

  • (String)

    The file extension.



12
# File 'lib/tahweel/writers/txt.rb', line 12

def extension = "txt"

#write(texts, destination, options = {}) ⇒ void

This method returns an undefined value.

Writes the extracted texts to a file.

Parameters:

  • texts (Array<String>)

    The extracted texts (one per page).

  • destination (String)

    The output file path.

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

    Options for writing.

Options Hash (options):

  • :page_separator (String) — default: PAGE_SEPARATOR

    Separator between pages.



21
22
23
24
# File 'lib/tahweel/writers/txt.rb', line 21

def write(texts, destination, options = {})
  separator = options[:page_separator] || PAGE_SEPARATOR
  File.write(destination, texts.map(&:strip).join(separator))
end