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, #has_children, #id, #json

Class Method Summary collapse

Instance Method Summary collapse

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

This class inherits a constructor from NotionRubyMapping::Base

Class Method Details

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

Parameters:

  • id (String)
  • dry_run (Boolean) (defaults to: false)

    true if dry_run

Returns:

See Also:



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

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

Instance Method Details

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

Returns obtained Page value or PropertyCache.

Parameters:

  • key (String)

Returns:



24
25
26
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 24

def [](key)
  get key
end

#append_comment(text_objects, dry_run: false) ⇒ Object

Parameters:

  • dry_run (Boolean) (defaults to: false)

    true if dry_run



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

def append_comment(text_objects, dry_run: false)
  rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
  json = rto.property_schema_json.merge({"parent" => {"page_id" => @id}})
  if dry_run
    self.class.dry_run_script :post, @nc.comments_path, json
  else
    CommentObject.new json: (@nc.append_comment_request json)
  end
end

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

Parameters:

  • title (String)
  • assigns (Array<String, Property>)

Yields:

Returns:

See Also:



43
44
45
46
47
48
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 43

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) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database, String

Parameters:

  • title (String)
  • assigns (Array<String, Property>)
  • dry_run (Boolean) (defaults to: false)

    true if dry_run

Yields:

Returns:

See Also:



55
56
57
58
59
60
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 55

def create_child_database(title, *assigns, dry_run: false)
  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.save dry_run: dry_run
end

#public_urlString

Returns 公開URL.

Returns:

  • (String)

    公開URL



63
64
65
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 63

def public_url
  @json["public_url"]
end

#titleString

Returns title.



69
70
71
72
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 69

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

#urlString

Returns URL.

Returns:

  • (String)

    URL



75
76
77
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 75

def url
  @json["url"]
end