Class: NotionRubyMapping::LinkToPageBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/notion_ruby_mapping/blocks/link_to_page_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, 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_icon, #synced_block_original?, #update_json

Constructor Details

#initialize(page_id: nil, database_id: nil, json: nil, id: nil, parent: nil) ⇒ LinkToPageBlock

Returns a new instance of LinkToPageBlock.

Parameters:

  • page_id (String) (defaults to: nil)
  • database_id (String) (defaults to: nil)

See Also:


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

def initialize(page_id: nil, database_id: nil, json: nil, id: nil, parent: nil)
  super(json: json, id: id, parent: parent)
  if @json
    @page_id, @database_id = @json[type].values_at(*%w[page_id database_id])
  else
    @page_id = page_id
    @database_id = database_id
  end
end

Instance Attribute Details

#database_idObject (readonly)


21
22
23
# File 'lib/notion_ruby_mapping/blocks/link_to_page_block.rb', line 21

def database_id
  @database_id
end

#page_idObject (readonly)


21
22
23
# File 'lib/notion_ruby_mapping/blocks/link_to_page_block.rb', line 21

def page_id
  @page_id
end

Instance Method Details

#block_json(not_update: true) ⇒ Hash{String (frozen)->Hash

Returns ].

Parameters:

  • not_update (Boolean) (defaults to: true)

    false when update

Returns:

  • (Hash{String (frozen)->Hash)

    ]


25
26
27
28
29
30
31
32
33
# File 'lib/notion_ruby_mapping/blocks/link_to_page_block.rb', line 25

def block_json(not_update: true)
  ans = super
  ans[type] = if @page_id
                {"type" => "page_id", "page_id" => Base.page_id(@page_id)}
              else
                {"type" => "database_id", "database_id" => Base.database_id(@database_id)}
              end
  ans
end

#typeString (frozen)

Returns:

  • (String (frozen))

36
37
38
# File 'lib/notion_ruby_mapping/blocks/link_to_page_block.rb', line 36

def type
  "link_to_page"
end