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, #copy, #cut, #descendants, #eq?, #find_all, #find_children, #find_first, #marks, #marks=, #node, #node_size, #nodes_between, #parse_content, #process_attrs_data, #raw_marks, #resolve, #text?, #text_content, #to_yaml
Constructor Details
#initialize(opts = {}) ⇒ TableRow
Returns a new instance of TableRow.
17 18 19 20 |
# File 'lib/prosereflect/table_row.rb', line 17 def initialize(opts = {}) opts[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
22 23 24 |
# File 'lib/prosereflect/table_row.rb', line 22 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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prosereflect/table_row.rb', line 31 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
26 27 28 |
# File 'lib/prosereflect/table_row.rb', line 26 def cells content || [] end |
#to_h ⇒ Object
Override to_h to handle empty content and attributes properly
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/prosereflect/table_row.rb', line 44 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 |