Class: NotionRubyMapping::Page

Inherits:
Base
  • Object
show all
Defined in:
lib/notion_ruby_mapping/blocks/page.rb

Overview

Notion page object

Instance Attribute Summary

Attributes inherited from Base

#archived, #id, #json

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#append_block_children, #assert_parent_children_pair, #assign_property, #block?, #children, create_from_json, #created_time, #database?, dry_run_script, #get, #icon, #initialize, #inspect, #json_properties, #last_edited_time, #new_record?, #page?, #parent, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_icon, #synced_block_original?, #update_json

Constructor Details

This class inherits a constructor from NotionRubyMapping::Base

Class Method Details

.find(id, dry_run: false) ⇒ NotionRubyMapping::Page, String



11
12
13
14
15
16
17
18
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 11

def self.find(id, dry_run: false)
  nc = NotionCache.instance
  if dry_run
    Base.dry_run_script :get, nc.page_path(id)
  else
    nc.page id
  end
end

Instance Method Details

#[](key) ⇒ NotionRubyMapping::PropertyCache, Hash



22
23
24
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 22

def [](key)
  get key
end

#build_child_database(title, *assigns) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database



30
31
32
33
34
35
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 30

def build_child_database(title, *assigns)
  db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
                    assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
  yield db, db.properties if block_given?
  db
end

#create_child_database(title, *assigns, dry_run: false) ⇒ NotionRubyMapping::Database



41
42
43
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 41

def create_child_database(title, *assigns, dry_run: false)
  build_child_database(title, *assigns).save dry_run: dry_run
end

#titleString

Returns title.



47
48
49
50
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 47

def title
  tp = properties.select { |p| (p.is_a?(TitleProperty)) || (p.is_a?(Property) && p.property_id == "title") }
  tp.map(&:full_text).join ""
end