Class: Paru::PandocFilter::Row

Inherits:
Block show all
Defined in:
lib/paru/filter/row.rb

Overview

A Row node represents a row in a table's head or body

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents = []) ⇒ Row

Create a new Row based on the row_data

Parameters:

  • contents (Array = []) (defaults to: [])

    the contents of this Row node



39
40
41
42
43
44
45
# File 'lib/paru/filter/row.rb', line 39

def initialize(contents = [])
    @attr = Attr.new contents[0]
    super []
    contents[1].each do |cell|
        @children.push Cell.new cell
    end
end

Instance Attribute Details

#attrObject

Returns Attr.

Returns:

  • Attr



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/paru/filter/row.rb', line 32

class Row < Block
    attr_accessor :attr

    # Create a new Row based on the row_data
    #
    # @param contents [Array = []] the contents of
    #   this Row node
    def initialize(contents = [])
        @attr = Attr.new contents[0]
        super []
        contents[1].each do |cell|
            @children.push Cell.new cell
        end
    end

    # The cells of this row
    #
    # @return [Array<Cell>]
    def cells()
      @children
    end

    # The AST contents of this Row
    #
    # @return [Array]
    def ast_contents
        [
          @attr.to_ast,
          @children.map {|child| child.to_ast}
        ]
    end

    # Create an AST representation of this Node
    #
    # @return [Hash]
    def to_ast()
      ast_contents()
    end

    # Convert this Row to an array of markdown strings, one for
    # each cell
    #
    # @return [String[]] An Array representation of this Row.
    def to_array()
        @children.map do |cell|
            cell.children.map{|c| c.markdown.strip}.join("\n")
        end
    end
end

#cellsArray<Cell>

The cells of this row

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/paru/filter/row.rb', line 32

class Row < Block
    attr_accessor :attr

    # Create a new Row based on the row_data
    #
    # @param contents [Array = []] the contents of
    #   this Row node
    def initialize(contents = [])
        @attr = Attr.new contents[0]
        super []
        contents[1].each do |cell|
            @children.push Cell.new cell
        end
    end

    # The cells of this row
    #
    # @return [Array<Cell>]
    def cells()
      @children
    end

    # The AST contents of this Row
    #
    # @return [Array]
    def ast_contents
        [
          @attr.to_ast,
          @children.map {|child| child.to_ast}
        ]
    end

    # Create an AST representation of this Node
    #
    # @return [Hash]
    def to_ast()
      ast_contents()
    end

    # Convert this Row to an array of markdown strings, one for
    # each cell
    #
    # @return [String[]] An Array representation of this Row.
    def to_array()
        @children.map do |cell|
            cell.children.map{|c| c.markdown.strip}.join("\n")
        end
    end
end

Instance Method Details

#ast_contentsArray

The AST contents of this Row

Returns:

  • (Array)


57
58
59
60
61
62
# File 'lib/paru/filter/row.rb', line 57

def ast_contents
    [
      @attr.to_ast,
      @children.map {|child| child.to_ast}
    ]
end

#to_arrayString[]

Convert this Row to an array of markdown strings, one for each cell

Returns:

  • (String[])

    An Array representation of this Row.



75
76
77
78
79
# File 'lib/paru/filter/row.rb', line 75

def to_array()
    @children.map do |cell|
        cell.children.map{|c| c.markdown.strip}.join("\n")
    end
end

#to_astHash

Create an AST representation of this Node

Returns:

  • (Hash)


67
68
69
# File 'lib/paru/filter/row.rb', line 67

def to_ast()
  ast_contents()
end