Class: NotionRubyMapping::Page
- Defined in:
- lib/notion_ruby_mapping/blocks/page.rb
Overview
Notion page object
Instance Attribute Summary
Attributes inherited from Base
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
- #create_child_database(title, *assigns, dry_run: false) ⇒ NotionRubyMapping::Database
-
#title ⇒ String
Title.
Methods inherited from Base
#append_block_children, #assert_parent_children_pair, #assign_property, #block?, #children, #comments, 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
Returns obtained Page value or PropertyCache.
22 23 24 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 22 def [](key) get key end |
#append_comment(text_objects, dry_run: false) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 26 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
40 41 42 43 44 45 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 40 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
51 52 53 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 51 def create_child_database(title, *assigns, dry_run: false) build_child_database(title, *assigns).save dry_run: dry_run end |
#title ⇒ String
Returns title.
57 58 59 60 |
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 57 def title tp = properties.select { |p| (p.is_a?(TitleProperty)) || (p.is_a?(Property) && p.property_id == "title") } tp.map(&:full_text).join "" end |