Class: NotionRubyMapping::Page
- 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
-
#[](key) ⇒ NotionRubyMapping::PropertyCache, Hash
Obtained Page value or PropertyCache.
- #append_comment(text_objects, dry_run: false) ⇒ Object
- #build_child_database(title, *assigns) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database
- #build_child_page(template_page: nil, position: nil) {|page, pp| ... } ⇒ NotionRubyMapping::Base
- #create_child_database(title, *assigns, dry_run: false) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database, String
- #create_child_page(template_page: nil, position: nil, dry_run: false) {|page, pp| ... } ⇒ NotionRubyMapping::Base
- #move_to(page_or_data_source, dry_run: false) ⇒ NotionRubyMapping::Page, String
-
#public_url ⇒ String
公開URL.
-
#title ⇒ String
Title.
-
#url ⇒ String
URL.
Methods inherited from Base
#append_block_children, #assert_parent_children_pair, #assign_property, #block?, block_id, #children, #comments, #cover, create_from_json, #created_time, #data_source?, data_source_id, #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
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.
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
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
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 |
#build_child_page(template_page: nil, position: nil) {|page, pp| ... } ⇒ NotionRubyMapping::Base
63 64 65 66 67 68 69 70 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 63 def build_child_page(template_page: nil, position: nil) page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id}, template_page: template_page, position: position pp = page.properties pp.clear_will_update yield page, pp if block_given? page end |
#create_child_database(title, *assigns, dry_run: false) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database, String
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 |
#create_child_page(template_page: nil, position: nil, dry_run: false) {|page, pp| ... } ⇒ NotionRubyMapping::Base
74 75 76 77 78 79 80 81 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 74 def create_child_page(template_page: nil, position: nil, dry_run: false) page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id}, template_page: template_page, position: position pp = page.properties pp.clear_will_update yield page, pp if block_given? page.save dry_run: dry_run end |
#move_to(page_or_data_source, dry_run: false) ⇒ NotionRubyMapping::Page, String
86 87 88 89 90 91 92 93 94 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 86 def move_to(page_or_data_source, dry_run: false) key = page_or_data_source.is_a?(Page) ? "page_id" : "data_source_id" json = {"parent" => {"type" => key, key => page_or_data_source.id}} if dry_run self.class.dry_run_script :post, @nc.move_page_path(@id), json else update_json @nc.move_page_request(@id, json) end end |
#public_url ⇒ String
Returns 公開URL.
97 98 99 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 97 def public_url @json["public_url"] end |
#title ⇒ String
Returns title.
103 104 105 106 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 103 def title tp = properties.select { |p| p.is_a?(TitleProperty) || (p.is_a?(Property) && p.property_id == :title) } tp.map(&:full_text).join "" end |
#url ⇒ String
Returns URL.
109 110 111 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 109 def url @json["url"] end |