Class: NotionRubyMapping::TableRowBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/notion_ruby_mapping/blocks/table_row_block.rb

Overview

Notion block

Instance Attribute Summary

Attributes inherited from Block

#can_append, #can_have_children, #caption, #color, #language, #rich_text_array, #url

Attributes inherited from Base

#archived, #has_children, #id, #json

Instance Method Summary collapse

Methods inherited from Block

#append_after, #children_block_json, decode_block, #decode_block_caption, #decode_block_rich_text_array, #decode_color, #destroy, find, type2class, #update, #update_block_json

Methods inherited from Base

#append_block_children, #assert_parent_children_pair, #assign_property, #block?, block_id, #children, #comments, #cover, create_from_json, #created_time, #database?, database_id, dry_run_script, #get, #icon, #inspect, #json_properties, #last_edited_time, #new_record?, #page?, page_id, #parent, #parent_id, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_cover, #set_icon, #synced_block_original?, #update_json

Constructor Details

#initialize(array_array_of_text_objects = [], table_width = 3, json: nil, id: nil, parent: nil) ⇒ TableRowBlock

Returns a new instance of TableRowBlock.

Parameters:

  • array_array_of_text_objects (Array<Array<String, TextObject>>) (defaults to: [])
  • table_width (Integer) (defaults to: 3)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/notion_ruby_mapping/blocks/table_row_block.rb', line 8

def initialize(array_array_of_text_objects = [], table_width = 3, json: nil, id: nil, parent: nil)
  super json: json, id: id, parent: parent
  if @json
    @cells = @json[type]["cells"].map { |cell| cell.map { |to| RichTextObject.create_from_json to } }
  else
    cc = array_array_of_text_objects.count
    raise StandardError, "table width must be #{table_width} (given array size is #{cc}" unless table_width == cc

    @cells = array_array_of_text_objects.map do |cell|
      Array(cell).map { |text_info| TextObject.text_object text_info }
    end
  end
  @can_have_children = false
end

Instance Method Details

#block_json(not_update: true) ⇒ Object



23
24
25
26
27
# File 'lib/notion_ruby_mapping/blocks/table_row_block.rb', line 23

def block_json(not_update: true)
  ans = super
  ans[type] = {"cells" => @cells.map { |cell| Array(cell).map(&:property_values_json) }}
  ans
end

#typeString (frozen)

Returns:

  • (String (frozen))


30
31
32
# File 'lib/notion_ruby_mapping/blocks/table_row_block.rb', line 30

def type
  "table_row"
end