filter_starts_with: NotionRubyMapping 解説 (61)

はじめに

NotionRubyMapping 解説の第61回目です。今日は値が特定の文字列で始まるものだけを抽出するfilter_starts_with をそれぞれのプロパティで確認してみます。まず、以前使っていたデータベースを取得します。

parent

irb(main):002> db = Database.find "https://www.notion.so/hkob/cad035c49e5346e78331cb5d05cbc754?v=a03e96ed79ad4d35808e7a08583396a0&pvs=4"
=> NotionRubyMapping::Database-cad035c49e5346e78331cb5d05cbc754

query_database のみ

まず何もフィルタをかけないデータベースの検索で件数が3件になることを確認します。

irb(main):003> db.query_database.count
=> 3

文字列に関する filter_starts_with は文字列が特定のキーワードで始まるものを抽出するものです。

irb(main):005> db.query_database(dps["Email"].filter_starts_with "abc").count
=> 1
irb(main):006> db.query_database(dps["Url"].filter_starts_with "https:").count
=> 1
irb(main):007> db.query_database(dps["Name"].filter_starts_with "New").count
=> 1
irb(main):008> db.query_database(dps["RichText"].filter_starts_with "Sample").count
=> 1
irb(main):009> db.query_database(dps["PhoneNumber"].filter_starts_with "080-").count
=> 1

おわりに

今日は、filter_start_with を解説しました。文字列を保持するプロパティでは特定の文字から始まるものだけを抽出します。

EmailProperty のマニュアルはこちらです。その他のプロパティもここから見てください。

EmailProperty

NotionRubyMapping解説