NestedLines (nested_lines v0.1.0)

Documentation for NestedLines.

Summary

Functions

Returns true if the line can be indented, false otherwise. Lines are 1-indexed.

Returns true if the line can be outdented, false otherwise. Lines are 1-indexed.

Indents a line based on its index, raises if the line cannot be indented. Child lines are also indented by one position. Lines are 1-indexed.

Output a string representation of the line numbers.

Construct a nested line representation from a list of string values.

Outdents a line based on its index, raises if the line cannot be outdented. Child lines are also outdented by one position. Lines are 1-indexed.

Types

@type line() :: [line_number()]
Link to this type

line_number()

@type line_number() :: 0..1
@type t() :: %NestedLines{lines: [line()]}

Functions

Link to this function

can_indent?(nested_lines, position)

@spec can_indent?(t(), pos_integer()) :: boolean()

Returns true if the line can be indented, false otherwise. Lines are 1-indexed.

Examples

iex> %NestedLines{lines: [[1], [0, 1], [0, 1]]} |> NestedLines.can_indent?(1)
false

iex> %NestedLines{lines: [[1], [0, 1], [0, 1]]} |> NestedLines.can_indent?(3)
true
Link to this function

can_outdent?(nested_lines, position)

@spec can_outdent?(t(), pos_integer()) :: boolean()

Returns true if the line can be outdented, false otherwise. Lines are 1-indexed.

Examples

iex> %NestedLines{lines: [[1], [0, 1], [0, 0, 1]]} |> NestedLines.can_outdent?(2)
true

iex> %NestedLines{lines: [[1], [0, 1], [1]]} |> NestedLines.can_outdent?(3)
false

iex> %NestedLines{lines: [[1], [1], [0, 1], [1]]} |> NestedLines.can_outdent?(3)
true
Link to this function

indent!(nested_lines, position)

@spec indent!(t(), pos_integer()) :: t()

Indents a line based on its index, raises if the line cannot be indented. Child lines are also indented by one position. Lines are 1-indexed.

Examples

iex> %NestedLines{lines: [[1], [1], [0, 1], [1]]} |> NestedLines.indent!(4)
%NestedLines{lines: [[1], [1], [0, 1], [0, 1]]}
Link to this function

line_numbers(nested_lines, starting_number \\ 1)

@spec line_numbers(t(), pos_integer()) :: [String.t()]

Output a string representation of the line numbers.

Examples

iex> %NestedLines{lines: [[1], [0, 1], [0, 1], [1], [0, 1], [0, 0, 1]]} |> NestedLines.line_numbers()
["1", "1.1", "1.2", "2", "2.1", "2.1.1"]
Link to this function

move_line(nested_lines, list)

Link to this function

new!(line_input)

@spec new!([String.t() | non_neg_integer()]) :: t()

Construct a nested line representation from a list of string values.

Examples

iex> NestedLines.new!(["1", "1.1", "1.2", "2", "2.1"])
%NestedLines{lines: [[1], [0, 1], [0, 1], [1], [0, 1]]}
Link to this function

outdent!(nested_lines, position)

Outdents a line based on its index, raises if the line cannot be outdented. Child lines are also outdented by one position. Lines are 1-indexed.

Examples

iex> %NestedLines{lines: [[1], [1], [0, 1], [0, 0, 1]]} |> NestedLines.outdent!(3)
%NestedLines{lines: [[1], [1], [1], [0, 1]]}