Class: Paru::PandocFilter::Row
- 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
-
#attr ⇒ Object
Attr.
-
#cells ⇒ Array<Cell>
The cells of this row.
Instance Method Summary collapse
-
#ast_contents ⇒ Array
The AST contents of this Row.
-
#initialize(contents = []) ⇒ Row
constructor
Create a new Row based on the row_data.
-
#to_array ⇒ String[]
Convert this Row to an array of markdown strings, one for each cell.
-
#to_ast ⇒ Hash
Create an AST representation of this Node.
Constructor Details
Instance Attribute Details
#attr ⇒ Object
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 |
#cells ⇒ Array<Cell>
The cells of this row
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_contents ⇒ Array
The AST contents of this Row
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_array ⇒ String[]
Convert this Row to an array of markdown strings, one for each cell
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_ast ⇒ Hash
Create an AST representation of this Node
67 68 69 |
# File 'lib/paru/filter/row.rb', line 67 def to_ast() ast_contents() end |