Results for: "module_function"

CSV::Table

A CSV::Table instance represents CSV data. (see class CSV).

The instance may have:

Instance Methods

CSV::Table has three groups of instance methods:

Creating a CSV::Table Instance

Commonly, a new CSV::Table instance is created by parsing CSV source using headers:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.class # => CSV::Table

You can also create an instance directly. See ::new.

Headers

If a table has headers, the headers serve as labels for the columns of data. Each header serves as the label for its column.

The headers for a CSV::Table object are stored as an Array of Strings.

Commonly, headers are defined in the first row of CSV source:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.headers # => ["Name", "Value"]

If no headers are defined, the Array is empty:

table = CSV::Table.new([])
table.headers # => []

Access Modes

CSV::Table provides three modes for accessing table data:

The access mode for aCSV::Table instance affects the behavior of some of its instance methods:

Row Mode

Set a table to row mode with method by_row!:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.by_row! # => #<CSV::Table mode:row row_count:4>

Specify a single row by an Integer index:

# Get a row.
table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
# Set a row, then get it.
table[1] = CSV::Row.new(['Name', 'Value'], ['bam', 3])
table[1] # => #<CSV::Row "Name":"bam" "Value":3>

Specify a sequence of rows by a Range:

# Get rows.
table[1..2] # => [#<CSV::Row "Name":"bam" "Value":3>, #<CSV::Row "Name":"baz" "Value":"2">]
# Set rows, then get them.
table[1..2] = [
  CSV::Row.new(['Name', 'Value'], ['bat', 4]),
  CSV::Row.new(['Name', 'Value'], ['bad', 5]),
]
table[1..2] # => [["Name", #<CSV::Row "Name":"bat" "Value":4>], ["Value", #<CSV::Row "Name":"bad" "Value":5>]]

Column Mode

Set a table to column mode with method by_col!:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.by_col! # => #<CSV::Table mode:col row_count:4>

Specify a column by an Integer index:

# Get a column.
table[0]
# Set a column, then get it.
table[0] = ['FOO', 'BAR', 'BAZ']
table[0] # => ["FOO", "BAR", "BAZ"]

Specify a column by its String header:

# Get a column.
table['Name'] # => ["FOO", "BAR", "BAZ"]
# Set a column, then get it.
table['Name'] = ['Foo', 'Bar', 'Baz']
table['Name'] # => ["Foo", "Bar", "Baz"]

Mixed Mode

In mixed mode, you can refer to either rows or columns:

Set a table to mixed mode with method by_col_or_row!:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>

Specify a single row by an Integer index:

# Get a row.
table[1] # => #<CSV::Row "Name":"bar" "Value":"1">
# Set a row, then get it.
table[1] = CSV::Row.new(['Name', 'Value'], ['bam', 3])
table[1] # => #<CSV::Row "Name":"bam" "Value":3>

Specify a sequence of rows by a Range:

# Get rows.
table[1..2] # => [#<CSV::Row "Name":"bam" "Value":3>, #<CSV::Row "Name":"baz" "Value":"2">]
# Set rows, then get them.
table[1] = CSV::Row.new(['Name', 'Value'], ['bat', 4])
table[2] = CSV::Row.new(['Name', 'Value'], ['bad', 5])
table[1..2] # => [["Name", #<CSV::Row "Name":"bat" "Value":4>], ["Value", #<CSV::Row "Name":"bad" "Value":5>]]

Specify a column by its String header:

# Get a column.
table['Name'] # => ["foo", "bat", "bad"]
# Set a column, then get it.
table['Name'] = ['Foo', 'Bar', 'Baz']
table['Name'] # => ["Foo", "Bar", "Baz"]
No documentation available
No documentation available
No documentation available

An entry in an ACL

Error raised by the DRbProtocol module when it cannot find any protocol implementation support the scheme specified in a URI.

An exception wrapping an error object

No documentation available
No documentation available

A custom InputMethod class used by XMP for evaluating string io.

No documentation available
No documentation available

Response class for Moved Permanently responses (status code 301).

The Moved Permanently response indicates that links or records returning this response should be updated to use the given URL.

References:

Response class for Found responses (status code 302).

The Found response indicates that the client should look at (browse to) another URL.

References:

Response class for Method Not Allowed responses (status code 405).

The request method is not supported for the requested resource.

References:

Response class for Not Acceptable responses (status code 406).

The requested resource is capable of generating only content that not acceptable according to the Accept headers sent in the request.

References:

Response class for Length Required responses (status code 411).

The request did not specify the length of its content, which is required by the requested resource.

References:

No documentation available
No documentation available
No documentation available

Raises when there is an argument for a switch which takes no argument.

PrettyPrint::SingleLine is used by PrettyPrint.singleline_format

It is passed to be similar to a PrettyPrint object itself, by responding to:

but instead, the output has no line breaks

A compiler is a visitor that returns the value of each node as it visits. This is as opposed to a visitor which will only walk the tree. This can be useful when you are trying to compile a tree into a different format.

For example, to build a representation of the tree as s-expressions, you could write:

class SExpressions < Prism::Compiler
  def visit_arguments_node(node) = [:arguments, super]
  def visit_call_node(node) = [:call, super]
  def visit_integer_node(node) = [:integer]
  def visit_program_node(node) = [:program, super]
end

Prism.parse("1 + 2").value.accept(SExpressions.new)
# => [:program, [[[:call, [[:integer], [:arguments, [[:integer]]]]]]]]

DesugarCompiler is a compiler that desugars Ruby code into a more primitive form. This is useful for consumers that want to deal with fewer node types.

No documentation available
Search took: 8ms  ·  Total Results: 4789