PlainTextHeadedStringTableParser

com.phasmidsoftware.tableparser.core.parse.PlainTextHeadedStringTableParser
case class PlainTextHeadedStringTableParser[X](maybeHeader: Option[Header] = ..., forgiving: Boolean = ..., headerRowsToRead: Int = ...)(using evidence$1: CellParser[X]) extends HeadedStringTableParser[X]

Case class to define a StringTableParser that assumes a header to be found in the input file. This class attempts to provide as much built-in functionality as possible.

This class assumes that the names of the columns are in the first line. This class implements builder with a HeadedTable object. This class uses StandardRowParser of its rowParser.

Type parameters

X

the underlying row type for which there must be evidence of a CellParser and ClassTag.

Value parameters

forgiving

if true, exceptions when parsing individual rows will be logged then ignored. if false, any exception will terminate the parsing. Defaults to false.

headerRowsToRead

the number of header rows expected in the input file defaults to 1.

maybeHeader

None => requires that the data source has a header row. Some(h) => specifies that the header is to be taken from h. Defaults to None. NOTE: that the simplest is to specify the header directly from the type X.

Attributes

See also

HeadedStringTableParser#create

Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait CopyableTableParser[X, String, Table[X]]
trait TableParser[Table[X]]
trait TableBuilder[Table[X]]
class Object
trait Matchable
class Any
Show all

Members list

Type members

Inherited types

type Input = String

The input type, typically String or Strings.

The input type, typically String or Strings.

Attributes

Inherited from:
StringTableParser
type Row = X

The row type.

The row type.

Attributes

Inherited from:
HeadedStringTableParser

Value members

Concrete methods

Configures the parser to operate in a "forgiving" mode, where errors encountered during the parsing of individual rows are logged but do not cause the parsing process to fail. When set to true, the parser will attempt to continue parsing despite encountering errors in the input. When set to false, errors will cause the parsing process to terminate.

Configures the parser to operate in a "forgiving" mode, where errors encountered during the parsing of individual rows are logged but do not cause the parsing process to fail. When set to true, the parser will attempt to continue parsing despite encountering errors in the input. When set to false, errors will cause the parsing process to terminate.

Value parameters

forgiving

a boolean value indicating whether forgiving mode should be enabled. true enables forgiving mode, allowing parsing to continue on errors. false disables forgiving mode, causing failures on errors.

Attributes

Returns

an instance of TableParser[Table] configured with the specified forgiving behavior.

Sets a fixed header for the table parser. This method allows the configuration of the parser to use the specified header, instead of deriving it from the data during parsing.

Sets a fixed header for the table parser. This method allows the configuration of the parser to use the specified header, instead of deriving it from the data during parsing.

Value parameters

header

the Header instance representing the fixed header for the table parser, containing column names and optional additional header lines.

Attributes

Returns

a new TableParser[Table] instance configured with the specified header.

Configures the parser to allow or disallow quoted strings to span across multiple lines.

Configures the parser to allow or disallow quoted strings to span across multiple lines.

When multiline is set to true, the parser permits quoted strings in the input to extend beyond a single line. If set to false, quoted strings are constrained to stay within one line.

Value parameters

multiline

a boolean flag indicating whether multiline parsing of quoted strings is enabled (true) or disabled (false).

Attributes

Returns

a new TableParser[Table] instance configured with the updated multiline setting.

def setPredicate(p: Try[X] => Boolean): PlainTextHeadedStringTableParser[X]

Sets a predicate function that determines whether a parsed Row should be included in the final Table. The predicate is applied to each parsed Row wrapped in a Try to allow filtering based on success or failure.

Sets a predicate function that determines whether a parsed Row should be included in the final Table. The predicate is applied to each parsed Row wrapped in a Try to allow filtering based on success or failure.

Value parameters

predicate

a function of type Try[Row] => Boolean that accepts a Try of a Row and returns true if the row should be included in the table, or false otherwise.

Attributes

Returns

a new instance of TableParser[Table] with the specified predicate applied.

Sets the row parser to be used for parsing rows in the table.

Sets the row parser to be used for parsing rows in the table.

The row parser provides the logic for converting raw input data of type Input into rows of type Row. This method allows you to configure the table parser with a custom row parser, enabling flexibility in interpreting the rows according to specific requirements.

Value parameters

rowParser

the RowParser instance to use for parsing rows. The RowParser defines how each input (of type Input) is transformed into a row (of type Row), potentially using a Header for additional context.

Attributes

Returns

a new TableParser instance configured with the specified row parser.

Inherited methods

def doParseRows(ts: Iterator[Input], header: Header, f: ((Input, Int)) => Try[Row])(using ev: Joinable[Input]): Try[Table[X]]

Parses rows of input data into a table representation.

Parses rows of input data into a table representation.

This method utilizes an IndexedInputToRowsAggregator to transform an iterator of inputs into rows using the provided header and transformation function. It processes the input, materializes the resulting rows into a list, and constructs a table representation from the processed rows and header.

Value parameters

ev

an implicit evidence parameter ensuring the input type adheres to the Joinable type class, which defines how input elements can be combined or validated during processing.

f

a transformation function that maps the Header to a function capable of transforming a tuple of input and its index into a Try[Row]. This function encapsulates row processing logic and error handling for each input element.

header

the Header containing column metadata to guide the transformation process.

ts

an iterator of inputs to be parsed into rows.

Attributes

Returns

a Try containing a Table if the parsing is successful, or an error in case of failure.

Inherited from:
AbstractTableParser
override def parse(xs: Iterator[String], n: Int = ...): Try[Table[X]]

Method to parse a table based on a sequence of Inputs. NOTE: this is required so that we can invoke this method with an Iterator[String].

Method to parse a table based on a sequence of Inputs. NOTE: this is required so that we can invoke this method with an Iterator[String].

Value parameters

n

the number of rows to drop (length of the header)--defaults to 1.

xs

the sequence of Inputs, one for each row

Attributes

Returns

a Try[Table].

Definition Classes
Inherited from:
StringTableParser
def parseRows(ws: Iterator[String], header: Header): Try[Table[X]]

Parses rows from an iterator of input strings (ws) using the provided header and row parsing logic.

Parses rows from an iterator of input strings (ws) using the provided header and row parsing logic.

This method utilizes the doParseRows function to process each row in the input iterator, applying the provided rowParser.parse function to convert input strings into logical rows, while using the header to guide parsing and interpretation of the input.

Value parameters

header

the Header object that describes the expected structure of the table (e.g., column names).

ws

an iterator over the input strings, where each string represents a row in the table.

Attributes

Returns

a Try of the parsed Table object. On success, it contains the resulting table; on failure, it contains the parsing error.

Inherited from:
StringTableParser
def parseSelected(xs: Iterator[String], selection: RowSelection, n: Int = ...): Try[Table[X]]

Method to parse the input into a Table of the selected rows (see rows). As in parse, if this parser isn't forgiving, a row which can't be parsed makes the result a Failure.

Method to parse the input into a Table of the selected rows (see rows). As in parse, if this parser isn't forgiving, a row which can't be parsed makes the result a Failure.

Value parameters

n

the number of header lines (defaults to headerRowsToRead).

selection

the rows to select (RFC 7111: see CsvFragment).

xs

the lines of the input.

Attributes

Returns

a Try[Table].

Inherited from:
StringTableParser
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
def rows(xs: Iterator[String], n: Int = ..., selection: RowSelection = ...): Try[(Header, Iterator[Try[Row]])]

Method to parse the input lazily, as a stream of rows rather than a Table (see, e.g., IOTable.stream). The header is read now (from the first n lines, unless this parser has a fixed header); each row is parsed only when it is pulled from the iterator. As in parse, the predicate selects the rows; and, if this parser is forgiving, a row which can't be parsed is logged and left out. Otherwise, it is a Failure in the iterator.

Method to parse the input lazily, as a stream of rows rather than a Table (see, e.g., IOTable.stream). The header is read now (from the first n lines, unless this parser has a fixed header); each row is parsed only when it is pulled from the iterator. As in parse, the predicate selects the rows; and, if this parser is forgiving, a row which can't be parsed is logged and left out. Otherwise, it is a Failure in the iterator.

The selection (of RFC 7111 rows: see CsvFragment) applies before the predicate, since its row numbers are those of the input.

Value parameters

n

the number of header lines (defaults to headerRowsToRead).

selection

the rows to select (by default, all of them).

xs

the lines of the input.

Attributes

Returns

a Try of the header and an Iterator of the rows (each a Try).

Inherited from:
StringTableParser

Inherited fields

protected val predicate: Try[Row] => Boolean

Predicate to filter rows. Defaults to including all rows.

Predicate to filter rows. Defaults to including all rows.

Attributes

Inherited from:
TableBuilder
val rowParser: RowParser[X, String]

Method to define a row parser.

Method to define a row parser.

Attributes

Returns

a RowParser[Row, Input].

Inherited from:
HeadedStringTableParser