Class: Prosereflect::TableRow
- Defined in:
- lib/prosereflect/table_row.rb
Constant Summary collapse
- PM_TYPE =
'table_row'
Class Method Summary collapse
Instance Method Summary collapse
-
#add_cell(content_text = nil, attrs: nil) ⇒ Object
Add a cell to the row.
- #cells ⇒ Object
-
#initialize(opts = {}) ⇒ TableRow
constructor
A new instance of TableRow.
-
#to_h ⇒ Object
Override to_h to handle empty content and attributes properly.
Methods inherited from Node
#add_child, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #text_content, #to_yaml
Constructor Details
#initialize(opts = {}) ⇒ TableRow
Returns a new instance of TableRow.
18 19 20 21 |
# File 'lib/prosereflect/table_row.rb', line 18 def initialize(opts = {}) opts[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
23 24 25 |
# File 'lib/prosereflect/table_row.rb', line 23 def self.create(attrs = nil) new(type: PM_TYPE, attrs: attrs, content: []) end |
Instance Method Details
#add_cell(content_text = nil, attrs: nil) ⇒ Object
Add a cell to the row
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prosereflect/table_row.rb', line 32 def add_cell(content_text = nil, attrs: nil) cell = TableCell.create(attrs) if content_text paragraph = cell.add_paragraph paragraph.add_text(content_text) end add_child(cell) cell end |
#cells ⇒ Object
27 28 29 |
# File 'lib/prosereflect/table_row.rb', line 27 def cells content || [] end |
#to_h ⇒ Object
Override to_h to handle empty content and attributes properly
45 46 47 48 49 50 51 52 53 |
# File 'lib/prosereflect/table_row.rb', line 45 def to_h result = super result['content'] ||= [] if result['attrs'] result['attrs'] = result['attrs'].is_a?(Hash) && result['attrs'][:attrs] ? result['attrs'][:attrs] : result['attrs'] result.delete('attrs') if result['attrs'].empty? end result end |