Saucexages v0.2.0 Saucexages.SauceBlock View Source

Represents a full SAUCE block, including both a SAUCE record and comments.

Used for in-memory representations of SAUCE data when reading and writing SAUCE. Can also be used to extract further metadata from SAUCE data such as font information, detailed data type and file type info, flags, and more.

Overall, a SAUCE Block serves to provide an Elixir-centric SAUCE representation and a common format and shape for working with other SAUCE related tasks and APIs. The SAUCE block stores the minimum fields for full encoding and decoding, while avoiding extra decoding or encoding steps when possible. For instance, more detailed information for file types can be obtained by using the data_type and file_type fields, but a SAUCE block avoids forcing this information on the consumer until required.

Fields

See Saucexages.Sauce for a full description of each field.

The main difference in terms of fields between a SAUCE binary or SAUCE record is that the SAUCE comment block is translated and encapsulated within a SAUCE block as a comments field. This allows for working with comments in a more natural way as a simple list of strings. comment_lines is no longer required as a specific field as it can be dynamically obtained from a SAUCE block. This is done to avoid error-prone synchronization of the comment contents with the comment lines.

The other major difference is that type dependent fields are encapsulated under media_info. This is to distinguish between the SAUCE spec’s notion of file type (an integer field) and the conceptual grouping of fields that are dependent on the combination of data type and file type. See Saucexages.MediaInfo for more info.

Link to this section Summary

Functions

Adds comments to a SAUCE block

Removes all comments from a SAUCE block

Calculates the number of comment lines in a SAUCE block or list of comments

Returns the data_type_id for the given SAUCE block

Returns a detailed map of all SAUCE block data

Returns a formatted version of comment lines using the given separator between comment lines

Creates a SAUCE block from a SAUCE record and optional list of SAUCE comments

Returns a detailed map of any file type info that can be converted per-file type. Only the detailed information is returned

Returns the media_type_id for the given SAUCE block

Creates a new SauceBlock struct from a MediaInfo and an optional field enumerable

Adds a comment to the beginning of the of the SAUCE comments

Returns a mapped version of the t_flags field as a tuple containing the field type as the first element and the field value as the second element

Returns a mapped version of the t_info_1 field as a tuple containing the field type as the first element and the field value as the second element

Returns a mapped version of the t_info_2 field as a tuple containing the field type as the first element and the field value as the second element

Returns a mapped version of the t_info_3 field as a tuple containing the field type as the first element and the field value as the second element

Returns a mapped version of the t_info_4 field as a tuple containing the field type as the first element and the field value as the second element

Returns a mapped version of the t_info_s field as a tuple containing the field type as the first element and the field value as the second element

Returns the type handle for the given SAUCE block. A type handle consists of a tuple of {file_type, data_type}, where there is a valid mapping between the two. Invalid types will be coerced to a type handle for :none by default

Link to this section Types

Link to this type t() View Source
t() :: %Saucexages.SauceBlock{
  author: String.t() | nil,
  comments: [String.t()],
  date: DateTime.t() | nil,
  group: String.t() | nil,
  media_info: Saucexages.MediaInfo.t(),
  title: String.t() | nil,
  version: String.t()
}

Link to this section Functions

Link to this function add_comments(sauce_block, comments) View Source
add_comments(t(), [String.t()] | String.t()) :: t()

Adds comments to a SAUCE block.

Link to this function clear_comments(sauce_block) View Source
clear_comments(t()) :: t()

Removes all comments from a SAUCE block.

Link to this function comment_lines(comments) View Source
comment_lines(t()) :: non_neg_integer()
comment_lines([String.t()]) :: non_neg_integer()

Calculates the number of comment lines in a SAUCE block or list of comments.

Returns the data_type_id for the given SAUCE block.

Link to this function details(sauce_block) View Source
details(t()) :: map()

Returns a detailed map of all SAUCE block data.

Useful for editors or specialized processing.

Examples

iex> sauce_block = %Saucexages.SauceBlock{version: "00", title: "cheese platter", author: "No Cursor", group: "Inconsequential",  date: ~D[1994-01-01],  media_info: %{file_type: 1, data_type: 1, t_flags: 17, t_info_1: 80, t_info_2: 250, t_info_s: "IBM VGA"}}
iex> Saucexages.SauceBlock.details(sauce_block)
%{
ansi_flags: %Saucexages.AnsiFlags{
  aspect_ratio: :modern,
  letter_spacing: :none,
  non_blink_mode?: true
},
author: "No Cursor",
character_width: 80,
comments: [],
data_type: 1,
data_type_id: :character,
date: ~D[1994-01-01],
file_type: 1,
font_id: :ibm_vga,
group: "Inconsequential",
media_type_id: :ansi,
name: "ANSi",
number_of_lines: 250,
title: "cheese platter",
version: "00"
}
Link to this function do_format_comments(comments, separator) View Source
Link to this function formatted_comments(sauce_block, separator \\ "\n") View Source
formatted_comments(t(), String.t()) :: String.t()
formatted_comments([String.t()], String.t()) :: String.t()

Returns a formatted version of comment lines using the given separator between comment lines.

Examples

iex> Saucexages.SauceBlock.formatted_comments(["200 lines of blood", "80 columns of sweat"], ", ")
"200 lines of blood, 80 columns of sweat"
Link to this function from_sauce_record(sauce_record, sauce_comments \\ []) View Source
from_sauce_record(Saucexages.SauceRecord.t(), [String.t()]) :: t()

Creates a SAUCE block from a SAUCE record and optional list of SAUCE comments.

Link to this function media_details(sauce_block) View Source
media_details(t()) :: map()

Returns a detailed map of any file type info that can be converted per-file type. Only the detailed information is returned.

Useful for editors or specialized processing.

Examples

iex> sauce_block = %Saucexages.SauceBlock{version: "00", media_info: %{file_type: 1, data_type: 1, t_flags: 17, t_info_1: 80, t_info_2: 250, t_info_s: "IBM VGA"}}
iex> Saucexages.SauceBlock.media_details(sauce_block)
%{
  ansi_flags: %Saucexages.AnsiFlags{
    aspect_ratio: :modern,
    letter_spacing: :none,
    non_blink_mode?: true
  },
  character_width: 80,
  data_type: 1,
  file_type: 1,
  font_id: :ibm_vga,
  number_of_lines: 250
}

Returns the media_type_id for the given SAUCE block.

Link to this function new(media_info, opts \\ []) View Source

Creates a new SauceBlock struct from a MediaInfo and an optional field enumerable.

Link to this function prepend_comment(sauce_block, comment) View Source
prepend_comment(t(), String.t()) :: t()

Adds a comment to the beginning of the of the SAUCE comments.

Link to this function t_flags(sauce_block) View Source
t_flags(t()) :: {atom(), term()}

Returns a mapped version of the t_flags field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function t_info_1(sauce_block) View Source
t_info_1(t()) :: {atom(), term()}

Returns a mapped version of the t_info_1 field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function t_info_2(sauce_block) View Source
t_info_2(t()) :: {atom(), term()}

Returns a mapped version of the t_info_2 field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function t_info_3(sauce_block) View Source
t_info_3(t()) :: {atom(), term()}

Returns a mapped version of the t_info_3 field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function t_info_4(sauce_block) View Source
t_info_4(t()) :: {atom(), term()}

Returns a mapped version of the t_info_4 field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function t_info_s(sauce_block) View Source
t_info_s(t()) :: {atom(), term()}

Returns a mapped version of the t_info_s field as a tuple containing the field type as the first element and the field value as the second element.

Link to this function type_handle(sauce_block) View Source
type_handle(t()) :: Saucexages.MediaInfo.type_handle()

Returns the type handle for the given SAUCE block. A type handle consists of a tuple of {file_type, data_type}, where there is a valid mapping between the two. Invalid types will be coerced to a type handle for :none by default.