StatusProperty(DB, Page): NotionRubyMapping 解説 (53)

はじめに

NotionRubyMapping 解説の第53回目です。全部解説したつもりでしたが、Status を忘れていました。Notion API からは StatusProperty の Schema が更新できないことから、作成していなかったためです。現在はデータベース内の最初のページを使って説明していきます。

New title

irb(main):002> page = Page.find "https://www.notion.so/hkob/619a113814134c759773175ac988b96a?pvs=4"
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

StatusProperty

仕方ないので、StatusProperty は GUI で作成します。

まず、UrlProperty を取得します。

irb(main):003> sp = page.properties["Status"]
=>
#<NotionRubyMapping::StatusProperty:0x0000000126cb3348

status で設定されているステータスが取得できます。初期状態では、未着手になります。英語環境で作成した場合には、Not started になるはずです。

irb(main):004> sp.status
=> {"id"=>"4c740470-10bd-4b60-bcd2-7e9457ccbf52", "name"=>"未着手", "color"=>"default"}

status = でステータスを更新できます。

irb(main):005> sp.status = "完了"
=> "完了"
irb(main):006> page.save
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

設定されたステータスが完了に設定されていることがわかります。

StatusProperty

おわりに

今回はページの StatusProperty の変更を説明しました。status は更新できるのですが、SelectProperty や MultiSelectProperty と異なり、データベースのスキーマ側は変更することはできません。

StatusProperty のマニュアルはこちらです。

StatusProperty

NotionRubyMapping解説