Class: NotionRubyMapping::SyncedBlock

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

Overview

Notion block

Instance Attribute Summary collapse

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, #update_json

Constructor Details

#initialize(block_id: nil, sub_blocks: nil, json: nil, id: nil, parent: nil) ⇒ SyncedBlock

Returns a new instance of SyncedBlock.

Parameters:



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

def initialize(block_id: nil, sub_blocks: nil, json: nil, id: nil, parent: nil)
  super json: json, id: id, parent: parent
  if @json
    synced_from = @json[type]["synced_from"]
    @block_id = synced_from && @nc.hex_id(synced_from["block_id"])
  else
    @block_id = Base.block_id block_id
    add_sub_blocks sub_blocks
  end
  @can_have_children = @block_id.nil?
end

Instance Attribute Details

#block_idObject (readonly)

Returns the value of attribute block_id.



20
21
22
# File 'lib/notion_ruby_mapping/blocks/synced_block.rb', line 20

def block_id
  @block_id
end

Instance Method Details

#block_json(not_update: true) ⇒ Object



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

def block_json(not_update: true)
  ans = super
  ans[type] = {"synced_from" => @block_id ? {"type" => "block_id", "block_id" => @nc.hex_id(@block_id)} : nil}
  ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
  ans
end

#synced_block_originalNotionRubyMapping::SyncedBlock



35
36
37
# File 'lib/notion_ruby_mapping/blocks/synced_block.rb', line 35

def synced_block_original
  @block_id && Block.find(@block_id)
end

#synced_block_original?Boolean

Returns true if synced_block & block_id is nil.

Returns:

  • (Boolean)

    true if synced_block & block_id is nil



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

def synced_block_original?
  @block_id.nil?
end

#synced_block_original_idString?

Returns:

  • (String, nil)


40
41
42
# File 'lib/notion_ruby_mapping/blocks/synced_block.rb', line 40

def synced_block_original_id
  @block_id
end

#typeString (frozen)

Returns:

  • (String (frozen))


45
46
47
# File 'lib/notion_ruby_mapping/blocks/synced_block.rb', line 45

def type
  "synced_block"
end