notion_ruby_mapping 4.0.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -1
  3. data/README.md +5 -3
  4. data/lib/notion_ruby_mapping/blocks/block.rb +51 -48
  5. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +4 -4
  6. data/lib/notion_ruby_mapping/blocks/callout_block.rb +6 -1
  7. data/lib/notion_ruby_mapping/blocks/divider_block.rb +4 -4
  8. data/lib/notion_ruby_mapping/blocks/equation_block.rb +2 -2
  9. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +48 -19
  10. data/lib/notion_ruby_mapping/blocks/file_block.rb +4 -2
  11. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +1 -1
  12. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +1 -1
  13. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +1 -1
  14. data/lib/notion_ruby_mapping/blocks/heading4_block.rb +1 -1
  15. data/lib/notion_ruby_mapping/blocks/list.rb +1 -1
  16. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +6 -5
  17. data/lib/notion_ruby_mapping/controllers/mermaid_data_source.rb +3 -3
  18. data/lib/notion_ruby_mapping/controllers/rich_text_array.rb +6 -1
  19. data/lib/notion_ruby_mapping/objects/equation_object.rb +6 -4
  20. data/lib/notion_ruby_mapping/objects/file_object.rb +50 -25
  21. data/lib/notion_ruby_mapping/objects/file_upload_object.rb +114 -68
  22. data/lib/notion_ruby_mapping/properties/button_property.rb +2 -2
  23. data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
  24. data/lib/notion_ruby_mapping/properties/created_time_property.rb +1 -1
  25. data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
  26. data/lib/notion_ruby_mapping/properties/files_property.rb +10 -16
  27. data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +0 -1
  28. data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +1 -1
  29. data/lib/notion_ruby_mapping/properties/multi_property.rb +1 -1
  30. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +11 -11
  31. data/lib/notion_ruby_mapping/properties/number_property.rb +2 -2
  32. data/lib/notion_ruby_mapping/properties/people_property.rb +24 -5
  33. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +2 -2
  34. data/lib/notion_ruby_mapping/properties/property.rb +14 -35
  35. data/lib/notion_ruby_mapping/properties/relation_property.rb +7 -7
  36. data/lib/notion_ruby_mapping/properties/rich_text_property.rb +0 -22
  37. data/lib/notion_ruby_mapping/properties/select_property.rb +11 -11
  38. data/lib/notion_ruby_mapping/properties/status_property.rb +50 -2
  39. data/lib/notion_ruby_mapping/properties/text_property.rb +59 -1
  40. data/lib/notion_ruby_mapping/properties/title_property.rb +0 -38
  41. data/lib/notion_ruby_mapping/properties/unique_id_property.rb +39 -3
  42. data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
  43. data/lib/notion_ruby_mapping/properties/verification_property.rb +8 -12
  44. data/lib/notion_ruby_mapping/version.rb +1 -1
  45. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e126e6dda7027a42155522291389804d27f1a009894ab6a96b1e85e25ff4660
4
- data.tar.gz: c97f3f01e37c33306334de9a5134326337cb55f711598b046c62387245924bec
3
+ metadata.gz: 4d8cbce3013176a87d6e023e5bbbd0b5ae6f5c43b437f50c3c6df468ce302d19
4
+ data.tar.gz: 0ea1f4d67320d4039a42eb156ba03a29595a4362c51a44f7541a874c735c257b
5
5
  SHA512:
6
- metadata.gz: b05a1a095ac2892a1ea5b2a3d0b1283a524ad20eb0eb14fdc62df77dbb77437d1a890b114cb46fd3df0e3d0a92841e09803e4476f9d43783aab16faba7c1ceaa
7
- data.tar.gz: e2164f5ad4f8805749b32e7a2355e21d638d29b5c7f2efa16e28a79b6659de37df89263ed4ebbca9f7a8a5f5ced209b9ba735fe949ffbf07e8ae786ee347a1f6
6
+ metadata.gz: 05a4e8f93a32115e06047aa0324879e63c5ec761d7b98e1cfc7c1df76033389705d1a25ca0b79a1b657dfb4df27b80fa4eeb0793ec21be359d3c2105cbe3f98c
7
+ data.tar.gz: cc86a8c085ed3da0b7905560c4f92ec8c627739480c3ee13a951f9b9c82bf0ec5cf042f0d888af7bc98a9ecaee788282d042b4de7961852c9cd3407ed8389ab6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [4.1.0] - 2026-08-23
4
+
5
+ ### Removed
6
+
7
+ - `Property#contents?`
8
+ - `Property#assert_database_property`
9
+ - `def_delegators :retrieve_page_property` and `extend Forwardable` in `Property`
10
+ (a workaround for the 2022-06-28 API version, made unnecessary by the 2022-08-31 update)
11
+
12
+ ### Changed
13
+
14
+ - `Property.create_from_json` now raises a `StandardError` when the given JSON has no `type` key
15
+ - Unsupported property types now raise a unified message:
16
+ `Unsupported property type: <type> (<name>). Please update notion_ruby_mapping.`
17
+ - `Property#update_from_json` now assigns the value whenever the key exists,
18
+ so `false` and empty values are reflected correctly
19
+ - `List#initialize` normalizes `query` to `Query.new` when `nil` is given
20
+ - `assert_*` methods use positive conditions and a consistent
21
+ `Database or DataSource property` wording
22
+
3
23
  ## [0.1.0] - 2022-02-07
4
24
 
5
- - Initial release
25
+ - Initial release
data/README.md CHANGED
@@ -143,9 +143,11 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
143
143
 
144
144
  ## 3. ChangeLog
145
145
 
146
- - 2027/7/14 [v4.0.2] Add clear method for DateProperty
147
- - 2027/5/4 [v4.0.1] Add retrieve / update / delete a comment
148
- - 2027/3/23 [v4.0.0] Add markdown support, headnig_4, toggle_heading_4, and position support for appending blocks
146
+ - 2026/9/7 [v4.2.0] Refactor file handling (move FileUploadObject into NotionRubyMapping, remove FileObject update tracking, and reject missing or empty file sources)
147
+ - 2026/8/23 [v4.1.0] Refactor Property base class (remove def_delegators and contents?, raise for unsupported property type)
148
+ - 2026/7/14 [v4.0.2] Add clear method for DateProperty
149
+ - 2026/5/4 [v4.0.1] Add retrieve / update / delete a comment
150
+ - 2026/3/23 [v4.0.0] Add markdown support, headnig_4, toggle_heading_4, and position support for appending blocks
149
151
  - 2026/1/25 [v3.0.6] add move page, list templates, and create child page to page
150
152
  - 2025/12/15 [v3.0.5] add AudioBlock
151
153
  - 2025/12/9 [v3.0.4] Fix the issue where page.parent could not be executed for pages with a data source as parent
@@ -14,54 +14,10 @@ module NotionRubyMapping
14
14
  end
15
15
  attr_reader :can_have_children, :can_append, :type, :rich_text_array, :url, :caption, :color, :language
16
16
 
17
- def self.type2class(type, has_children = false)
18
- @type2class ||= {
19
- false => {
20
- audio: AudioBlock,
21
- bookmark: BookmarkBlock,
22
- breadcrumb: BreadcrumbBlock,
23
- bulleted_list_item: BulletedListItemBlock,
24
- callout: CalloutBlock,
25
- child_database: ChildDatabaseBlock,
26
- child_page: ChildPageBlock,
27
- code: CodeBlock,
28
- column: ColumnBlock,
29
- column_list: ColumnListBlock,
30
- divider: DividerBlock,
31
- embed: EmbedBlock,
32
- equation: EquationBlock,
33
- file: FileBlock,
34
- heading_1: Heading1Block,
35
- heading_2: Heading2Block,
36
- heading_3: Heading3Block,
37
- heading_4: Heading4Block,
38
- image: ImageBlock,
39
- link_preview: LinkPreviewBlock,
40
- link_to_page: LinkToPageBlock,
41
- numbered_list_item: NumberedListItemBlock,
42
- paragraph: ParagraphBlock,
43
- pdf: PdfBlock,
44
- quote: QuoteBlock,
45
- synced_block: SyncedBlock,
46
- table: TableBlock,
47
- table_row: TableRowBlock,
48
- table_of_contents: TableOfContentsBlock,
49
- to_do: ToDoBlock,
50
- toggle: ToggleBlock,
51
- video: VideoBlock,
52
- },
53
- true => {
54
- heading_1: ToggleHeading1Block,
55
- heading_2: ToggleHeading2Block,
56
- heading_3: ToggleHeading3Block,
57
- heading_4: ToggleHeading4Block,
58
- },
59
- }
60
- @klass = @type2class[has_children][type.to_sym] || @type2class[false][type.to_sym] || Block
61
- end
62
-
63
17
  def self.decode_block(json)
64
- type2class(json["type"], json["has_children"]).new json: json
18
+ type = json["type"]
19
+ is_toggleable = !!(json[type] && json[type]["is_toggleable"])
20
+ type2class(type, is_toggleable).new json: json
65
21
  end
66
22
 
67
23
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
@@ -101,7 +57,7 @@ module NotionRubyMapping
101
57
 
102
58
  # @return [NotionRubyMapping::RichTextArray]
103
59
  def decode_block_caption
104
- @caption = RichTextArray.new "caption", json: @json[type]["caption"] if @json[type]["caption"]
60
+ @caption = RichTextArray.new "caption", json: @json[type]["caption"] || []
105
61
  end
106
62
 
107
63
  # @return [String]
@@ -154,5 +110,52 @@ module NotionRubyMapping
154
110
  @color = color
155
111
  self
156
112
  end
113
+
114
+ def self.type2class(type, is_toggleable = false)
115
+ @type2class ||= {
116
+ false => {
117
+ audio: AudioBlock,
118
+ bookmark: BookmarkBlock,
119
+ breadcrumb: BreadcrumbBlock,
120
+ bulleted_list_item: BulletedListItemBlock,
121
+ callout: CalloutBlock,
122
+ child_database: ChildDatabaseBlock,
123
+ child_page: ChildPageBlock,
124
+ code: CodeBlock,
125
+ column: ColumnBlock,
126
+ column_list: ColumnListBlock,
127
+ divider: DividerBlock,
128
+ embed: EmbedBlock,
129
+ equation: EquationBlock,
130
+ file: FileBlock,
131
+ heading_1: Heading1Block,
132
+ heading_2: Heading2Block,
133
+ heading_3: Heading3Block,
134
+ heading_4: Heading4Block,
135
+ image: ImageBlock,
136
+ link_preview: LinkPreviewBlock,
137
+ link_to_page: LinkToPageBlock,
138
+ numbered_list_item: NumberedListItemBlock,
139
+ paragraph: ParagraphBlock,
140
+ pdf: PdfBlock,
141
+ quote: QuoteBlock,
142
+ synced_block: SyncedBlock,
143
+ table: TableBlock,
144
+ table_row: TableRowBlock,
145
+ table_of_contents: TableOfContentsBlock,
146
+ to_do: ToDoBlock,
147
+ toggle: ToggleBlock,
148
+ video: VideoBlock,
149
+ },
150
+ true => {
151
+ heading_1: ToggleHeading1Block,
152
+ heading_2: ToggleHeading2Block,
153
+ heading_3: ToggleHeading3Block,
154
+ heading_4: ToggleHeading4Block,
155
+ },
156
+ }
157
+ @type2class[is_toggleable][type.to_sym] || @type2class[false][type.to_sym] || Block
158
+ end
159
+ private_class_method :type2class
157
160
  end
158
161
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- # Notion block
4
+ # Notion breadcrumb block
5
5
  class BreadcrumbBlock < Block
6
- # @return [String (frozen)]
6
+ # @return [String] block type
7
7
  def type
8
8
  "breadcrumb"
9
9
  end
10
10
 
11
- # @param [Boolean] not_update false when update
12
- # @return [Hash{String (frozen)->Hash}]
11
+ # @param [Boolean] not_update true for a full block payload; false for an update payload
12
+ # @return [Hash{String => Object}] block payload
13
13
  def block_json(not_update: true)
14
14
  ans = super
15
15
  ans[type] = {}
@@ -14,8 +14,13 @@ module NotionRubyMapping
14
14
  if @json
15
15
  decode_block_rich_text_array
16
16
  decode_color
17
+ @emoji = json[type]&.dig("icon", "emoji")&.then { |str| EmojiObject.new emoji: str }
18
+ @file_object = json[type]&.dig("icon")&.then { |file_json| FileObject.new json: file_json }
17
19
  else
18
20
  rich_text_array_and_color "rich_text", text_info, color
21
+ raise ArgumentError, "Specify either emoji or file_url." if emoji.nil? && file_url.nil?
22
+ raise ArgumentError, "Specify either emoji or file_url, not both." if !emoji.nil? && !file_url.nil?
23
+
19
24
  @emoji = EmojiObject.emoji_object emoji if emoji
20
25
  @file_object = FileObject.file_object file_url if file_url
21
26
  add_sub_blocks sub_blocks
@@ -34,7 +39,7 @@ module NotionRubyMapping
34
39
  ans[type] = @rich_text_array.update_property_schema_json not_update
35
40
  ans[type]["color"] = @color
36
41
  ans[type]["icon"] = @emoji.property_values_json if @emoji
37
- ans[type]["icon"] = @file_object.property_values_json if @file_object
42
+ ans[type]["icon"] = @file_object.property_values_json if @file_object && @file_object.url
38
43
  ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
39
44
  ans
40
45
  end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- # Notion block
4
+ # Notion divider block
5
5
  class DividerBlock < Block
6
- # @param [Boolean] not_update false when update
7
- # @return [Hash{String (frozen)->Hash}]
6
+ # @param [Boolean] not_update true for a full block payload; false for an update payload
7
+ # @return [Hash{String => Object}] block payload
8
8
  def block_json(not_update: true)
9
9
  ans = super
10
10
  ans[type] = {}
11
11
  ans
12
12
  end
13
13
 
14
- # @return [String (frozen)]
14
+ # @return [String] block type
15
15
  def type
16
16
  "divider"
17
17
  end
@@ -3,7 +3,7 @@
3
3
  module NotionRubyMapping
4
4
  # Notion block
5
5
  class EquationBlock < Block
6
- # @param [String, NotionRubyMapping::EquationObject] expression
6
+ # @param [String, NotionRubyMapping::EquationObject, nil] expression
7
7
  # @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#cfcd2ceb77194c0e915500b429e8b91b
8
8
  def initialize(expression = nil, json: nil, id: nil, parent: nil)
9
9
  super(json: json, id: id, parent: parent)
@@ -28,7 +28,7 @@ module NotionRubyMapping
28
28
  @equation_object&.expression
29
29
  end
30
30
 
31
- # @param [String] new_expression
31
+ # @param [String, nil] new_expression
32
32
  # @see https://www.notion.so/hkob/EquationBlock-df0f823dc5ac41b798052f161dd6540c#f05e3b2c82914cea9f05e9e6644647e1
33
33
  def expression=(new_expression)
34
34
  @equation_object = EquationObject.equation_object new_expression
@@ -1,12 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- # Notion block
4
+ # Base class for blocks that contain a file and an optional caption.
5
+ #
6
+ # This class manages the file representation, caption, and update payload
7
+ # shared by file-based block types.
8
+ # @abstract Subclass and implement {#type}.
5
9
  class FileBaseBlock < Block
6
- # @param [String, FileUploadObject, NilClass] url or file upload object
7
- # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] caption
8
- # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#ace53d2e6ff2404f937179ae1e966e98
9
- # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#4cb790b8b5c847acab4341d55e4fa66a
10
+ # Creates a file-based block.
11
+ #
12
+ # @param url_or_fuo [String, FileUploadObject, FileObject, nil]
13
+ # an external URL, a file upload object, or a file object
14
+ # @param caption [RichTextArray, String, Array<String>, RichTextObject,
15
+ # Array<RichTextObject>, nil] caption content
16
+ # @param json [Hash, nil] block JSON returned by the Notion API
17
+ # @param id [String, nil] block ID
18
+ # @param parent [Page, Block, nil] parent object
10
19
  def initialize(url_or_fuo = nil, caption: [], json: nil, id: nil, parent: nil)
11
20
  super(json: json, id: id, parent: parent)
12
21
  if @json
@@ -19,12 +28,18 @@ module NotionRubyMapping
19
28
  end
20
29
  end
21
30
 
22
- # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#158487a7e1644fae8778dcff59869356
23
- # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#19a4aa3e06514bbe84be9d3b8a45a20f
24
- attr_reader :caption, :file_object
31
+ # @return [RichTextArray] block caption
32
+ attr_reader :caption
25
33
 
26
- # @param [Boolean] not_update false when update
27
- # @return [Hash{String (frozen)->Hash}]
34
+ # @return [FileObject] current file representation
35
+ attr_reader :file_object
36
+
37
+ # Builds the block JSON representation.
38
+ #
39
+ # @param not_update [Boolean] true for a complete block payload;
40
+ # false for an update payload
41
+ # @return [Hash{String => Object}] block JSON
42
+ # @api private
28
43
  def block_json(not_update: true)
29
44
  ans = super
30
45
  ans[type] = @file_object.property_values_json
@@ -32,27 +47,41 @@ module NotionRubyMapping
32
47
  ans
33
48
  end
34
49
 
35
- # @return [String]
36
- # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#d3e7d31b7b274955aa7603163867fa57
37
- # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#01e1883119f14c5f9f7f6823793e72ec
50
+ # Returns the current file URL.
51
+ #
52
+ # A URL returned for a Notion-hosted file may expire.
53
+ #
54
+ # @return [String, nil] current file URL
38
55
  def url
39
56
  @file_object&.url
40
57
  end
41
58
 
42
- # @param [String] url
43
- # @see https://www.notion.so/hkob/FileBlock-08f2aa6948364d00b92beacaac9a619c#23497b8eb2214c45b3d5881796f984cb
44
- # @see https://www.notion.so/hkob/ImageBlock-806b3d2a9a2c4bf5a5aca6e3fbc8a7e2#61598d260b6140f2a359f7d22ea2548a
59
+ # Replaces the current file with an external URL.
60
+ #
61
+ # Call {Block#save} to send the change to the Notion API.
62
+ #
63
+ # @param url [String] new external URL
45
64
  def url=(url)
46
65
  @file_object.url = url
47
66
  @payload.add_update_block_key "external"
48
67
  end
49
68
 
50
- # @param [FileUploadObject] fuo
51
- def file_upload_object=(fuo)
52
- @file_object.file_upload_object = fuo
69
+ # Replaces the current file with an uploaded file.
70
+ #
71
+ # Call {Block#save} to send the change to the Notion API. After saving,
72
+ # the file is reconstructed as a Notion-hosted file.
73
+ #
74
+ # @param file_upload_object [FileUploadObject] uploaded file
75
+ def file_upload_object=(file_upload_object)
76
+ @file_object.file_upload_object = file_upload_object
53
77
  @payload.add_update_block_key "file_upload"
54
78
  end
55
79
 
80
+ # Reconstructs the file and caption from an API response.
81
+ #
82
+ # @param json [Hash] block JSON returned by the Notion API
83
+ # @return [void]
84
+ # @api private
56
85
  def update_file_object_from_json(json)
57
86
  @file_object = FileObject.new json: json[type]
58
87
  decode_block_caption
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- # Notion block
4
+ # Represents a Notion file block.
5
5
  class FileBlock < FileBaseBlock
6
- # @return [String]
6
+ # Returns the Notion block type.
7
+ #
8
+ # @return [String] `"file"`
7
9
  def type
8
10
  "file"
9
11
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class Heading1Block < TextSubBlockColorBaseBlock
6
6
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>, nil] text_info
7
7
  # @param [String] color
8
- def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
8
+ def initialize(text_info = nil, color: "default", json: nil, id: nil, parent: nil)
9
9
  super(text_info, color: color, json: json, id: id, parent: parent)
10
10
  @can_have_children = false
11
11
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class Heading2Block < TextSubBlockColorBaseBlock
6
6
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
7
  # @param [String] color
8
- def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
8
+ def initialize(text_info = nil, color: "default", json: nil, id: nil, parent: nil)
9
9
  super(text_info, color: color, json: json, id: id, parent: parent)
10
10
  @can_have_children = false
11
11
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class Heading3Block < TextSubBlockColorBaseBlock
6
6
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
7
  # @param [String] color
8
- def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
8
+ def initialize(text_info = nil, color: "default", json: nil, id: nil, parent: nil)
9
9
  super(text_info, color: color, json: json, id: id, parent: parent)
10
10
  @can_have_children = false
11
11
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class Heading4Block < TextSubBlockColorBaseBlock
6
6
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
7
7
  # @param [String] color
8
- def initialize(text_info = nil, color: nil, json: nil, id: nil, parent: nil)
8
+ def initialize(text_info = nil, color: "default", json: nil, id: nil, parent: nil)
9
9
  super(text_info, color: color, json: json, id: id, parent: parent)
10
10
  @can_have_children = false
11
11
  end
@@ -26,7 +26,7 @@ module NotionRubyMapping
26
26
  when "template"
27
27
  @template = value
28
28
  end
29
- @query = query
29
+ @query = query || Query.new
30
30
  @index = 0
31
31
  @has_content = true
32
32
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- # Notion block
5
- # @param [String] color
4
+ # Notion table of contents block
6
5
  class TableOfContentsBlock < Block
6
+ # @param [String] color block color
7
7
  def initialize(color = "default", json: nil, id: nil, parent: nil)
8
8
  super(json: json, id: id, parent: parent)
9
9
  if @json
@@ -13,18 +13,19 @@ module NotionRubyMapping
13
13
  end
14
14
  end
15
15
 
16
+ # @param [String] new_color new block color
16
17
  def color=(new_color)
17
18
  @color = new_color
18
19
  @payload.add_update_block_key "color"
19
20
  end
20
21
 
21
- # @return [String (frozen)]
22
+ # @return [String] block type
22
23
  def type
23
24
  "table_of_contents"
24
25
  end
25
26
 
26
- # @param [Boolean] not_update false when update
27
- # @return [Hash{String (frozen)->Hash}]
27
+ # @param [Boolean] not_update true for a full block payload; false for an update payload
28
+ # @return [Hash{String => Object}] block payload
28
29
  def block_json(not_update: true)
29
30
  ans = super
30
31
  ans[type] = {"color" => @color}
@@ -96,7 +96,7 @@ module NotionRubyMapping
96
96
 
97
97
  when "multi_select"
98
98
  if property
99
- (options - (property.multi_select_options.map { |h| h["name"] })).each do |select_name|
99
+ (options - property.multi_select_options.map { |h| h["name"] }).each do |select_name|
100
100
  property.add_multi_select_option name: select_name, color: "default"
101
101
  end
102
102
  else
@@ -145,7 +145,7 @@ module NotionRubyMapping
145
145
  end
146
146
  when "select"
147
147
  if property
148
- (options - (property.select_options.map { |h| h["name"] })).each do |select_name|
148
+ (options - property.select_options.map { |h| h["name"] }).each do |select_name|
149
149
  property.add_select_option name: select_name, color: "default"
150
150
  end
151
151
  else
@@ -165,7 +165,7 @@ module NotionRubyMapping
165
165
  property = ps.values_at(forward).first
166
166
  if property
167
167
  if reverse
168
- if property.data_source_id == db_is && property.synced_property_name == reverse
168
+ if property.relation_data_source_id == db_is && property.synced_property_name == reverse
169
169
  relation_ds.add_property "relation", reverse
170
170
  relation_ds.finish_flag[reverse] = true
171
171
  else
@@ -19,13 +19,14 @@ module NotionRubyMapping
19
19
  end
20
20
  @will_update = will_update
21
21
  end
22
+ attr_reader :rich_text_objects
22
23
  attr_writer :will_update
23
24
 
24
25
  def self.rich_text_array(key, text_objects = nil)
25
26
  if text_objects.nil?
26
27
  RichTextArray.new key
27
28
  elsif text_objects.is_a? RichTextArray
28
- text_objects
29
+ RichTextArray.new key, text_objects: text_objects.rich_text_objects
29
30
  else
30
31
  RichTextArray.new key, text_objects: text_objects
31
32
  end
@@ -79,6 +80,10 @@ module NotionRubyMapping
79
80
  map(&:text).join ""
80
81
  end
81
82
 
83
+ def clear
84
+ self.rich_text_objects = []
85
+ end
86
+
82
87
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
83
88
  def rich_text_objects=(text_info)
84
89
  @will_update = true
@@ -3,16 +3,17 @@
3
3
  module NotionRubyMapping
4
4
  # EquationObject
5
5
  class EquationObject < RichTextObject
6
- # @param [String] expression
7
- # @return [TextObject]
6
+ # @param [String, nil] expression
7
+ # @return [EquationObject]
8
8
  def initialize(expression, options = {})
9
+ expression ||= ""
9
10
  super "equation", {"plain_text" => expression}.merge(options)
10
11
  @expression = expression
11
12
  @will_update = false
12
13
  end
13
14
  attr_reader :will_update, :expression
14
15
 
15
- # @param [EquationObject, String] uo
16
+ # @param [EquationObject, String, nil] expression_or_eo
16
17
  # @return [EquationObject] self or created EquationObject
17
18
  # @see https://www.notion.so/hkob/EquationObject-cd50126fce544ad5bb76463a4269859b#45b0b0810d8647a1968a5e4293920aeb
18
19
  def self.equation_object(expression_or_eo)
@@ -23,9 +24,10 @@ module NotionRubyMapping
23
24
  end
24
25
  end
25
26
 
26
- # @param [String] expression
27
+ # @param [String, nil] expression
27
28
  # @see https://www.notion.so/hkob/EquationObject-cd50126fce544ad5bb76463a4269859b#155800e2c69d4676a2d74572ed8f0de8
28
29
  def expression=(expression)
30
+ expression ||= ""
29
31
  @expression = expression
30
32
  @options["plain_text"] = expression
31
33
  @will_update = true