notion_ruby_mapping 0.8.9 → 1.0.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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -1
  3. data/lib/notion_ruby_mapping/blocks/base.rb +33 -33
  4. data/lib/notion_ruby_mapping/blocks/block.rb +48 -47
  5. data/lib/notion_ruby_mapping/blocks/bookmark_block.rb +1 -1
  6. data/lib/notion_ruby_mapping/blocks/breadcrumb_block.rb +1 -1
  7. data/lib/notion_ruby_mapping/blocks/bulleted_list_item_block.rb +1 -1
  8. data/lib/notion_ruby_mapping/blocks/callout_block.rb +10 -10
  9. data/lib/notion_ruby_mapping/blocks/child_base_block.rb +2 -2
  10. data/lib/notion_ruby_mapping/blocks/child_database_block.rb +3 -3
  11. data/lib/notion_ruby_mapping/blocks/child_page_block.rb +3 -3
  12. data/lib/notion_ruby_mapping/blocks/code_block.rb +7 -7
  13. data/lib/notion_ruby_mapping/blocks/column_block.rb +3 -3
  14. data/lib/notion_ruby_mapping/blocks/column_list_block.rb +2 -2
  15. data/lib/notion_ruby_mapping/blocks/database.rb +6 -6
  16. data/lib/notion_ruby_mapping/blocks/divider_block.rb +1 -1
  17. data/lib/notion_ruby_mapping/blocks/embed_block.rb +2 -2
  18. data/lib/notion_ruby_mapping/blocks/equation_block.rb +5 -5
  19. data/lib/notion_ruby_mapping/blocks/file_base_block.rb +2 -2
  20. data/lib/notion_ruby_mapping/blocks/file_block.rb +1 -1
  21. data/lib/notion_ruby_mapping/blocks/heading1_block.rb +4 -4
  22. data/lib/notion_ruby_mapping/blocks/heading2_block.rb +2 -2
  23. data/lib/notion_ruby_mapping/blocks/heading3_block.rb +3 -3
  24. data/lib/notion_ruby_mapping/blocks/image_block.rb +1 -1
  25. data/lib/notion_ruby_mapping/blocks/link_preview_block.rb +2 -2
  26. data/lib/notion_ruby_mapping/blocks/link_to_page_block.rb +5 -5
  27. data/lib/notion_ruby_mapping/blocks/list.rb +21 -20
  28. data/lib/notion_ruby_mapping/blocks/numbered_list_item_block.rb +2 -2
  29. data/lib/notion_ruby_mapping/blocks/page.rb +9 -10
  30. data/lib/notion_ruby_mapping/blocks/paragraph_block.rb +2 -2
  31. data/lib/notion_ruby_mapping/blocks/pdf_block.rb +2 -2
  32. data/lib/notion_ruby_mapping/blocks/quote_block.rb +1 -1
  33. data/lib/notion_ruby_mapping/blocks/synced_block.rb +5 -5
  34. data/lib/notion_ruby_mapping/blocks/table_block.rb +8 -8
  35. data/lib/notion_ruby_mapping/blocks/table_of_contents_block.rb +3 -3
  36. data/lib/notion_ruby_mapping/blocks/table_row_block.rb +3 -3
  37. data/lib/notion_ruby_mapping/blocks/template_block.rb +3 -3
  38. data/lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb +4 -4
  39. data/lib/notion_ruby_mapping/blocks/to_do_block.rb +4 -4
  40. data/lib/notion_ruby_mapping/blocks/toggle_block.rb +2 -2
  41. data/lib/notion_ruby_mapping/blocks/toggle_heading1_block.rb +2 -2
  42. data/lib/notion_ruby_mapping/blocks/toggle_heading2_block.rb +2 -2
  43. data/lib/notion_ruby_mapping/blocks/toggle_heading3_block.rb +3 -3
  44. data/lib/notion_ruby_mapping/blocks/url_base_block.rb +3 -3
  45. data/lib/notion_ruby_mapping/blocks/url_caption_base_block.rb +4 -4
  46. data/lib/notion_ruby_mapping/blocks/video_block.rb +2 -2
  47. data/lib/notion_ruby_mapping/controllers/discussion_thread.rb +1 -1
  48. data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +34 -34
  49. data/lib/notion_ruby_mapping/controllers/notion_cache.rb +6 -8
  50. data/lib/notion_ruby_mapping/controllers/payload.rb +11 -11
  51. data/lib/notion_ruby_mapping/controllers/property_cache.rb +8 -7
  52. data/lib/notion_ruby_mapping/controllers/query.rb +10 -10
  53. data/lib/notion_ruby_mapping/controllers/search.rb +5 -6
  54. data/lib/notion_ruby_mapping/objects/comment_object.rb +2 -2
  55. data/lib/notion_ruby_mapping/objects/emoji_object.rb +3 -3
  56. data/lib/notion_ruby_mapping/objects/equation_object.rb +3 -3
  57. data/lib/notion_ruby_mapping/objects/file_object.rb +9 -9
  58. data/lib/notion_ruby_mapping/objects/mention_object.rb +43 -43
  59. data/lib/notion_ruby_mapping/objects/rich_text_object.rb +43 -43
  60. data/lib/notion_ruby_mapping/objects/text_object.rb +5 -5
  61. data/lib/notion_ruby_mapping/objects/user_object.rb +4 -4
  62. data/lib/notion_ruby_mapping/properties/button_property.rb +4 -4
  63. data/lib/notion_ruby_mapping/properties/checkbox_property.rb +3 -3
  64. data/lib/notion_ruby_mapping/properties/created_by_property.rb +3 -3
  65. data/lib/notion_ruby_mapping/properties/created_time_property.rb +2 -2
  66. data/lib/notion_ruby_mapping/properties/date_base_property.rb +14 -13
  67. data/lib/notion_ruby_mapping/properties/date_property.rb +17 -17
  68. data/lib/notion_ruby_mapping/properties/email_property.rb +3 -3
  69. data/lib/notion_ruby_mapping/properties/files_property.rb +16 -13
  70. data/lib/notion_ruby_mapping/properties/formula_property.rb +7 -7
  71. data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -2
  72. data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +2 -2
  73. data/lib/notion_ruby_mapping/properties/multi_select_property.rb +15 -15
  74. data/lib/notion_ruby_mapping/properties/number_property.rb +9 -9
  75. data/lib/notion_ruby_mapping/properties/people_property.rb +6 -6
  76. data/lib/notion_ruby_mapping/properties/phone_number_property.rb +4 -4
  77. data/lib/notion_ruby_mapping/properties/property.rb +78 -75
  78. data/lib/notion_ruby_mapping/properties/relation_property.rb +18 -17
  79. data/lib/notion_ruby_mapping/properties/rich_text_property.rb +5 -5
  80. data/lib/notion_ruby_mapping/properties/rollup_property.rb +15 -15
  81. data/lib/notion_ruby_mapping/properties/select_property.rb +14 -14
  82. data/lib/notion_ruby_mapping/properties/status_property.rb +5 -5
  83. data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
  84. data/lib/notion_ruby_mapping/properties/title_property.rb +6 -6
  85. data/lib/notion_ruby_mapping/properties/unique_id_property.rb +3 -3
  86. data/lib/notion_ruby_mapping/properties/url_property.rb +3 -3
  87. data/lib/notion_ruby_mapping/properties/verification_property.rb +3 -3
  88. data/lib/notion_ruby_mapping/version.rb +1 -1
  89. data/notion_ruby_mapping.gemspec +1 -2
  90. metadata +4 -22
  91. data/sig/notion_ruby_mapping.rbs +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd6b2157ccc35fd74afcb19e5c3a1f79a47fc85bbd37a40615244d7ab0e94dcc
4
- data.tar.gz: 8a8b3a3a816159cf1759ffef5bc2a3c2a8cd4533fa0aa85591c6a0079fb8e8c7
3
+ metadata.gz: 0d1066cd6c3332c90c8370e13f4cc52e9e729b29df0726ebad6279825d56f2a6
4
+ data.tar.gz: 85a67ad41b4ffb73578568e804c395b9fd0fb0f69ac6b535c3ddef0f8927e6e5
5
5
  SHA512:
6
- metadata.gz: d39c8c323487e2cad1782dd3b19a9f3a02b6c843fe31a4d61dc4ddd23af7de1f81f22c4a29a085ffe510d76186738c99246f1bb2f7fd87c8b0085db8c74d3bed
7
- data.tar.gz: 18d4e3bdc38409ff21a76e76129a1b208c28ab539d02f9fa17662b70d1d56dbab084bda4cd467fccafab421174b55b9fc8556f1e19f39e35a2953cffefe68f5f
6
+ metadata.gz: 3356a1466bae782aee4e51f6b14849e7c7a429b692bc0f6cb1108190d42f12231ca48975e3cd17cb271ac015d38f68d7aafd22edf9b6688e0e4ecd3ab7d59c8d
7
+ data.tar.gz: 4272a59512daad50200fb919483a2b36044fa5dd875c20289b90871a0e276b0771b3f6235eae94df09421afbf862f1fb8f8726a6efb0b11f79b0ade0dfbdab04
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  require: rubocop-rspec
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.6
4
+ TargetRubyVersion: 3.0
5
5
 
6
6
  Style/StringLiterals:
7
7
  Enabled: true
@@ -26,6 +26,17 @@ Style/TrailingCommaInArrayLiteral:
26
26
  Style/TrailingCommaInHashLiteral:
27
27
  EnforcedStyleForMultiline: comma
28
28
 
29
+ Naming/VariableNumber:
30
+ EnforcedStyle: snake_case
31
+
32
+ RSpec/NestedGroups:
33
+ Enabled: true
34
+ MaxNesting: 5
35
+
36
+ RSpec/MultipleMemoizedHelpers:
37
+ Enabled: true
38
+ Max: 8
39
+
29
40
  Metrics/BlockLength:
30
41
  Exclude:
31
42
  - "Rakefile"
@@ -10,13 +10,13 @@ module NotionRubyMapping
10
10
  def initialize(json: nil, id: nil, assign: [], parent: nil)
11
11
  @nc = NotionCache.instance
12
12
  @json = json
13
- @id = @nc.hex_id(id || @json && @json["id"])
14
- @archived = @json && @json["archived"]
15
- @has_children = @json && @json["has_children"]
13
+ @id = @nc.hex_id(id || @json && @json[:id])
14
+ @archived = @json && @json[:archived]
15
+ @has_children = @json && @json[:has_children]
16
16
  @new_record = true unless parent.nil?
17
17
  raise StandardError, "Unknown id" if !is_a?(List) && !is_a?(Block) && @id.nil? && parent.nil?
18
18
 
19
- @payload = Payload.new(!is_a?(Block) && parent && {"parent" => parent})
19
+ @payload = Payload.new(!is_a?(Block) && parent && {parent: parent})
20
20
  @property_cache = nil
21
21
  @created_time = nil
22
22
  @last_edited_time = nil
@@ -30,14 +30,14 @@ module NotionRubyMapping
30
30
  # @param [Hash, Notion::Messages] json
31
31
  # @return [NotionRubyMapping::Base]
32
32
  def self.create_from_json(json)
33
- case json["object"]
34
- when "page"
33
+ case json[:object]&.to_sym
34
+ when :page
35
35
  Page.new json: json
36
- when "database"
36
+ when :database
37
37
  Database.new json: json
38
- when "list"
38
+ when :list
39
39
  List.new json: json
40
- when "block"
40
+ when :block
41
41
  Block.decode_block json
42
42
  else
43
43
  raise StandardError, json.inspect
@@ -90,7 +90,7 @@ module NotionRubyMapping
90
90
  self.class.dry_run_script :get, @nc.retrieve_comments_path(@id)
91
91
  else
92
92
  ans = {}
93
- List.new(type: :comment_parent, value: self,
93
+ List.new(type: "comment_parent", value: self,
94
94
  json: @nc.retrieve_comments_request(@id, query),
95
95
  query: query).each do |comment|
96
96
  dt_id = comment.discussion_id
@@ -110,7 +110,7 @@ module NotionRubyMapping
110
110
  reload
111
111
  end
112
112
  case key
113
- when "properties"
113
+ when :properties
114
114
  properties
115
115
  else
116
116
  @json[key]
@@ -128,20 +128,20 @@ module NotionRubyMapping
128
128
 
129
129
  only_one = blocks.length == 1
130
130
  json = {
131
- "children" => Array(blocks).map do |block|
131
+ children: Array(blocks).map do |block|
132
132
  assert_parent_children_pair block
133
133
  block.block_json
134
134
  end,
135
135
  }
136
- json["after"] = after if after
136
+ json[:after] = after if after
137
137
  if dry_run
138
138
  path = @nc.append_block_children_page_path(id)
139
139
  self.class.dry_run_script :patch, path, json
140
140
  else
141
141
  response = @nc.append_block_children_request @id, json
142
- raise StandardError, response unless response["results"]
142
+ raise StandardError, response unless response[:results]
143
143
 
144
- answers = response["results"].map { |sub_json| Block.create_from_json sub_json }
144
+ answers = response[:results].map { |sub_json| Block.create_from_json sub_json }
145
145
  only_one ? answers.first : answers
146
146
  end
147
147
  end
@@ -155,10 +155,10 @@ module NotionRubyMapping
155
155
  return if block.can_append
156
156
 
157
157
  bt = block.type
158
- raise StandardError, "Internal file block can not append." if bt == "file"
158
+ raise StandardError, "Internal file block can not append." if bt == :file
159
159
 
160
- raise StandardError, "Column block can only append column_list block" unless bt == "column" &&
161
- block? && type == "column_list"
160
+ raise StandardError, "Column block can only append column_list block" unless bt == :column &&
161
+ block? && type == :column_list
162
162
  end
163
163
 
164
164
  # @param [NotionRubyMapping::Property] klass
@@ -199,7 +199,7 @@ module NotionRubyMapping
199
199
 
200
200
  # @return [NotionRubyMapping::CreatedTimeProperty]
201
201
  def created_time
202
- @created_time ||= CreatedTimeProperty.new("__timestamp__", json: self["created_time"])
202
+ @created_time ||= CreatedTimeProperty.new("__timestamp__", json: self[:created_time])
203
203
  end
204
204
 
205
205
  # @return [TrueClass, FalseClass] true if Database object
@@ -210,7 +210,7 @@ module NotionRubyMapping
210
210
  # @return [Hash, nil] obtained Hash
211
211
  # @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e13d526bd709451e9b06fd32e8d07fcd
212
212
  def icon
213
- self["icon"]
213
+ self[:icon]
214
214
  end
215
215
 
216
216
  # @return [String (frozen)]
@@ -220,12 +220,12 @@ module NotionRubyMapping
220
220
 
221
221
  # @return [Hash] json properties
222
222
  def json_properties
223
- @json && @json["properties"]
223
+ @json && @json[:properties]
224
224
  end
225
225
 
226
226
  # @return [NotionRubyMapping::LastEditedTimeProperty]
227
227
  def last_edited_time
228
- @last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self["last_edited_time"])
228
+ @last_edited_time ||= LastEditedTimeProperty.new("__timestamp__", json: self[:last_edited_time])
229
229
  end
230
230
 
231
231
  # @return [Boolean] true if new record
@@ -241,16 +241,16 @@ module NotionRubyMapping
241
241
 
242
242
  # @param [Boolean] dry_run true if dry_run
243
243
  def parent(dry_run: false)
244
- parent_json = @json && @json["parent"]
244
+ parent_json = @json && @json[:parent]
245
245
  raise StandardError, "Unknown parent" if parent_json.nil?
246
246
 
247
- type = parent_json["type"]
247
+ type = parent_json[:type]&.to_sym
248
248
  klass = case type
249
- when "database_id"
249
+ when :database_id
250
250
  Database
251
- when "page_id"
251
+ when :page_id
252
252
  Page
253
- when "block_id"
253
+ when :block_id
254
254
  Block
255
255
  else
256
256
  raise StandardError, "List does not have any parent"
@@ -259,10 +259,10 @@ module NotionRubyMapping
259
259
  end
260
260
 
261
261
  def parent_id
262
- parent_json = @json && @json["parent"]
262
+ parent_json = @json && @json[:parent]
263
263
  raise StandardError, "Unknown parent" if parent_json.nil?
264
264
 
265
- parent_json[parent_json["type"]]
265
+ parent_json[parent_json[:type]]
266
266
  end
267
267
 
268
268
  # @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
@@ -294,13 +294,13 @@ module NotionRubyMapping
294
294
 
295
295
  # @return [NotionRubyMapping::Base]
296
296
  def restore_from_json
297
- return if (ps = @json["properties"]).nil?
297
+ return if (ps = @json[:properties]).nil?
298
298
 
299
299
  properties.json = json_properties
300
300
  return unless is_a?(Page) || is_a?(Database)
301
301
 
302
302
  ps.each do |key, json|
303
- if json["type"]
303
+ if json[:type]
304
304
  properties[key].update_from_json json
305
305
  else
306
306
  properties[key]&.clear_will_update
@@ -341,13 +341,13 @@ module NotionRubyMapping
341
341
  # @param [Hash] json
342
342
  # @return [NotionRubyMapping::Base]
343
343
  def update_json(json)
344
- unless json["object"] != "error" && (@json.nil? || @json["type"] == json["type"])
344
+ unless json[:object] != "error" && (@json.nil? || @json[:type] == json[:type])
345
345
  raise StandardError,
346
346
  json.inspect
347
347
  end
348
348
 
349
349
  @json = json
350
- @id = @nc.hex_id(@json["id"])
350
+ @id = @nc.hex_id(@json[:id])
351
351
  restore_from_json
352
352
  self
353
353
  end
@@ -15,51 +15,52 @@ module NotionRubyMapping
15
15
  attr_reader :can_have_children, :can_append, :type, :rich_text_array, :url, :caption, :color, :language
16
16
 
17
17
  def self.type2class(type, has_children = false)
18
+ type_sym = type.to_sym
18
19
  @type2class ||= {
19
20
  false => {
20
- "bookmark" => BookmarkBlock,
21
- "breadcrumb" => BreadcrumbBlock,
22
- "bulleted_list_item" => BulletedListItemBlock,
23
- "callout" => CalloutBlock,
24
- "child_database" => ChildDatabaseBlock,
25
- "child_page" => ChildPageBlock,
26
- "code" => CodeBlock,
27
- "column" => ColumnBlock,
28
- "column_list" => ColumnListBlock,
29
- "divider" => DividerBlock,
30
- "embed" => EmbedBlock,
31
- "equation" => EquationBlock,
32
- "file" => FileBlock,
33
- "heading_1" => Heading1Block,
34
- "heading_2" => Heading2Block,
35
- "heading_3" => Heading3Block,
36
- "image" => ImageBlock,
37
- "link_preview" => LinkPreviewBlock,
38
- "link_to_page" => LinkToPageBlock,
39
- "numbered_list_item" => NumberedListItemBlock,
40
- "paragraph" => ParagraphBlock,
41
- "pdf" => PdfBlock,
42
- "quote" => QuoteBlock,
43
- "synced_block" => SyncedBlock,
44
- "table" => TableBlock,
45
- "table_row" => TableRowBlock,
46
- "table_of_contents" => TableOfContentsBlock,
47
- "template" => TemplateBlock,
48
- "to_do" => ToDoBlock,
49
- "toggle" => ToggleBlock,
50
- "video" => VideoBlock,
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
+ image: ImageBlock,
38
+ link_preview: LinkPreviewBlock,
39
+ link_to_page: LinkToPageBlock,
40
+ numbered_list_item: NumberedListItemBlock,
41
+ paragraph: ParagraphBlock,
42
+ pdf: PdfBlock,
43
+ quote: QuoteBlock,
44
+ synced_block: SyncedBlock,
45
+ table: TableBlock,
46
+ table_row: TableRowBlock,
47
+ table_of_contents: TableOfContentsBlock,
48
+ template: TemplateBlock,
49
+ to_do: ToDoBlock,
50
+ toggle: ToggleBlock,
51
+ video: VideoBlock,
51
52
  },
52
53
  true => {
53
- "heading_1" => ToggleHeading1Block,
54
- "heading_2" => ToggleHeading2Block,
55
- "heading_3" => ToggleHeading3Block,
56
- }
54
+ heading_1: ToggleHeading1Block,
55
+ heading_2: ToggleHeading2Block,
56
+ heading_3: ToggleHeading3Block,
57
+ },
57
58
  }
58
- @klass = @type2class[has_children][type] || @type2class[false][type] || Block
59
+ @klass = @type2class[has_children][type_sym] || @type2class[false][type_sym] || Block
59
60
  end
60
61
 
61
62
  def self.decode_block(json)
62
- type2class(json["type"], json["has_children"]).new json: json
63
+ type2class(json[:type], json[:has_children]).new json: json
63
64
  end
64
65
 
65
66
  # @see https://www.notion.so/hkob/Block-689ad4cbff50404d8a1baf67b6d6d78d#298916c7c379424682f39ff09ee38544
@@ -80,36 +81,36 @@ module NotionRubyMapping
80
81
  # @return [NotionRubyMapping::Block, String]
81
82
  # @param [Array<Block>] blocks
82
83
  def append_after(*blocks, dry_run: false)
83
- parent.append_block_children *blocks, after: id, dry_run: dry_run
84
+ parent.append_block_children(*blocks, after: id, dry_run: dry_run)
84
85
  end
85
86
 
86
87
  # @param [Boolean] not_update false when update
87
88
  # @return [Hash{String (frozen)->Hash}]
88
89
  def block_json(not_update: true)
89
- ans = {"type" => type}
90
- ans["object"] = "block"
91
- ans["archived"] = true if @archived
90
+ ans = {type: type.to_s}
91
+ ans[:object] = "block"
92
+ ans[:archived] = true if @archived
92
93
  ans
93
94
  end
94
95
 
95
96
  # @return [Hash{String (frozen)->Array<Hash{String (frozen)->Hash}>}]
96
97
  def children_block_json
97
- {"children" => [block_json]}
98
+ {children: [block_json]}
98
99
  end
99
100
 
100
101
  # @return [NotionRubyMapping::RichTextArray]
101
102
  def decode_block_caption
102
- @caption = RichTextArray.new "caption", json: @json[type]["caption"]
103
+ @caption = RichTextArray.new :caption, json: @json[type][:caption]
103
104
  end
104
105
 
105
106
  # @return [String]
106
107
  def decode_color
107
- @color = @json[type]["color"]
108
+ @color = @json[type][:color]
108
109
  end
109
110
 
110
111
  # @return [NotionRubyMapping::RichTextArray]
111
112
  def decode_block_rich_text_array
112
- @rich_text_array = RichTextArray.new "rich_text", json: @json[type]["rich_text"]
113
+ @rich_text_array = RichTextArray.new :rich_text, json: @json[type][:rich_text]
113
114
  end
114
115
 
115
116
  # @param [Boolean] dry_run true if dry_run
@@ -144,10 +145,10 @@ module NotionRubyMapping
144
145
  @can_have_children = true
145
146
  end
146
147
 
147
- # @param [String] type
148
+ # @param [String, Symbol] type
148
149
  # @param [String] color
149
150
  def rich_text_array_and_color(type, text_info, color = "default")
150
- @rich_text_array = RichTextArray.rich_text_array type, text_info
151
+ @rich_text_array = RichTextArray.rich_text_array type.to_sym, text_info
151
152
  @color = color
152
153
  self
153
154
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class BookmarkBlock < UrlCaptionBaseBlock
6
6
  # @return [String (frozen)]
7
7
  def type
8
- "bookmark"
8
+ :bookmark
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class BreadcrumbBlock < Block
6
6
  # @return [String (frozen)]
7
7
  def type
8
- "breadcrumb"
8
+ :breadcrumb
9
9
  end
10
10
 
11
11
  # @param [Boolean] not_update false when update
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class BulletedListItemBlock < TextSubBlockColorBaseBlock
6
6
  # @return [String (frozen)]
7
7
  def type
8
- "bulleted_list_item"
8
+ :bulleted_list_item
9
9
  end
10
10
  end
11
11
  end
@@ -15,7 +15,7 @@ module NotionRubyMapping
15
15
  decode_block_rich_text_array
16
16
  decode_color
17
17
  else
18
- rich_text_array_and_color "rich_text", text_info, color
18
+ rich_text_array_and_color :rich_text, text_info, color
19
19
  @emoji = EmojiObject.emoji_object emoji if emoji
20
20
  @file_object = FileObject.file_object file_url if file_url
21
21
  add_sub_blocks sub_blocks
@@ -32,10 +32,10 @@ module NotionRubyMapping
32
32
  def block_json(not_update: true)
33
33
  ans = super
34
34
  ans[type] = @rich_text_array.update_property_schema_json not_update
35
- ans[type]["color"] = @color
36
- ans[type]["icon"] = @emoji.property_values_json if @emoji
37
- ans[type]["icon"] = @file_object.property_values_json if @file_object
38
- ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
35
+ ans[type][:color] = @color
36
+ ans[type][:icon] = @emoji.property_values_json if @emoji
37
+ ans[type][:icon] = @file_object.property_values_json if @file_object
38
+ ans[type][:children] = @sub_blocks.map(&:block_json) if @sub_blocks
39
39
  ans
40
40
  end
41
41
 
@@ -43,7 +43,7 @@ module NotionRubyMapping
43
43
  # @see https://www.notion.so/hkob/CalloutBlock-0eb8b64bea664bc89fad706a866a6e26#b3598e385c2d4a23ada506441a7f0f32
44
44
  def color=(new_color)
45
45
  @color = new_color
46
- @payload.add_update_block_key "color"
46
+ @payload.add_update_block_key :color
47
47
  end
48
48
 
49
49
  # @return [String, nil]
@@ -57,7 +57,7 @@ module NotionRubyMapping
57
57
  def emoji=(emoji)
58
58
  @emoji = EmojiObject.emoji_object emoji
59
59
  @file_object = nil
60
- @payload.add_update_block_key "icon"
60
+ @payload.add_update_block_key :icon
61
61
  end
62
62
 
63
63
  # @return [String]
@@ -71,12 +71,12 @@ module NotionRubyMapping
71
71
  def file_url=(url)
72
72
  @file_object = FileObject.file_object url
73
73
  @emoji = nil
74
- @payload.add_update_block_key "icon"
74
+ @payload.add_update_block_key :icon
75
75
  end
76
76
 
77
- # @return [String (frozen)]
77
+ # @return [Symbol]
78
78
  def type
79
- "callout"
79
+ :callout
80
80
  end
81
81
  end
82
82
  end
@@ -5,7 +5,7 @@ module NotionRubyMapping
5
5
  class ChildBaseBlock < Block
6
6
  def initialize(json: nil, id: nil, parent: nil)
7
7
  super
8
- @title = @json[type]["title"]
8
+ @title = @json[type][:title]
9
9
  @can_append = false
10
10
  @can_append = false
11
11
  end
@@ -14,7 +14,7 @@ module NotionRubyMapping
14
14
  # @return [Hash{String (frozen)->Hash}]
15
15
  def block_json(not_update: true)
16
16
  ans = super
17
- ans[type] = {"title" => @title}
17
+ ans[type] = {title: @title}
18
18
  ans
19
19
  end
20
20
  end
@@ -3,13 +3,13 @@
3
3
  module NotionRubyMapping
4
4
  # Notion block
5
5
  class ChildDatabaseBlock < ChildBaseBlock
6
- # @return [String (frozen)]
6
+ # @return [Symbol]
7
7
  def type
8
- "child_database"
8
+ :child_database
9
9
  end
10
10
 
11
11
  def title
12
- @json[type]["title"]
12
+ @json[type][:title]
13
13
  end
14
14
  end
15
15
  end
@@ -3,13 +3,13 @@
3
3
  module NotionRubyMapping
4
4
  # Notion block
5
5
  class ChildPageBlock < ChildBaseBlock
6
- # @return [String (frozen)]
6
+ # @return [Symbol]
7
7
  def type
8
- "child_page"
8
+ :child_page
9
9
  end
10
10
 
11
11
  def title
12
- @json[type]["title"]
12
+ @json[type][:title]
13
13
  end
14
14
  end
15
15
  end
@@ -12,10 +12,10 @@ module NotionRubyMapping
12
12
  if @json
13
13
  decode_block_rich_text_array
14
14
  decode_block_caption
15
- @language = json[type]["language"] || "shell"
15
+ @language = json[type][:language] || "shell"
16
16
  else
17
- rich_text_array_and_color "rich_text", text_info
18
- @caption = RichTextArray.rich_text_array "caption", caption
17
+ rich_text_array_and_color :rich_text, text_info
18
+ @caption = RichTextArray.rich_text_array :caption, caption
19
19
  @language = language
20
20
  end
21
21
  end
@@ -32,19 +32,19 @@ module NotionRubyMapping
32
32
  ans[type] = @rich_text_array.update_property_schema_json(not_update).merge(
33
33
  @caption.update_property_schema_json(not_update),
34
34
  )
35
- ans[type]["language"] = @language
35
+ ans[type][:language] = @language
36
36
  ans
37
37
  end
38
38
 
39
39
  # @param [String] new_language
40
40
  def language=(new_language)
41
41
  @language = new_language
42
- @payload.add_update_block_key "language"
42
+ @payload.add_update_block_key :language
43
43
  end
44
44
 
45
- # @return [String (frozen)]
45
+ # @return [Symbol]
46
46
  def type
47
- "code"
47
+ :code
48
48
  end
49
49
  end
50
50
  end
@@ -12,9 +12,9 @@ module NotionRubyMapping
12
12
  @can_append = false
13
13
  end
14
14
 
15
- # @return [String (frozen)]
15
+ # @return [Symbol]
16
16
  def type
17
- "column"
17
+ :column
18
18
  end
19
19
 
20
20
  # @param [Boolean] not_update false when update
@@ -22,7 +22,7 @@ module NotionRubyMapping
22
22
  def block_json(not_update: true)
23
23
  ans = super
24
24
  ans[type] = {}
25
- ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
25
+ ans[type][:children] = @sub_blocks.map(&:block_json) if @sub_blocks
26
26
  ans
27
27
  end
28
28
  end
@@ -18,7 +18,7 @@ module NotionRubyMapping
18
18
 
19
19
  # @return [String (frozen)]
20
20
  def type
21
- "column_list"
21
+ :column_list
22
22
  end
23
23
 
24
24
  # @param [Boolean] not_update false when update
@@ -26,7 +26,7 @@ module NotionRubyMapping
26
26
  def block_json(not_update: true)
27
27
  ans = super
28
28
  ans[type] = {}
29
- ans[type]["children"] = @columns.map(&:block_json) if @columns
29
+ ans[type][:children] = @columns.map(&:block_json) if @columns
30
30
  ans
31
31
  end
32
32
  end
@@ -42,7 +42,7 @@ module NotionRubyMapping
42
42
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
43
43
  def build_child_page(*assign)
44
44
  assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
45
- page = Page.new assign: assign, parent: {"database_id" => @id}
45
+ page = Page.new assign: assign, parent: {database_id: @id}
46
46
  pp = page.properties
47
47
  pp.clear_will_update
48
48
  yield page, pp if block_given?
@@ -55,7 +55,7 @@ module NotionRubyMapping
55
55
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#c217ce78020a4de79b720790fce3092d
56
56
  def create_child_page(*assign, dry_run: false)
57
57
  assign = properties.map { |p| [p.class, p.name] }.flatten if assign.empty?
58
- page = Page.new assign: assign, parent: {"database_id" => @id}
58
+ page = Page.new assign: assign, parent: {database_id: @id}
59
59
  pp = page.properties
60
60
  pp.clear_will_update
61
61
  yield page, pp if block_given?
@@ -65,12 +65,12 @@ module NotionRubyMapping
65
65
  # @return [NotionRubyMapping::RichTextArray]
66
66
  # @see https://www.notion.so/hkob/Database-1462b24502424539a4231bedc07dc2f5#217a7d988c404d68b270c4874a9117b4
67
67
  def database_title
68
- @database_title ||= RichTextArray.new "title", json: (self["title"]), will_update: new_record?
68
+ @database_title ||= RichTextArray.new :title, json: (self[:title]), will_update: new_record?
69
69
  end
70
70
 
71
71
  # @return [NotionRubyMapping::RichTextArray]
72
72
  def description
73
- RichTextArray.new "description", json: self["description"]
73
+ RichTextArray.new :description, json: self[:description]
74
74
  end
75
75
 
76
76
  # @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
@@ -80,7 +80,7 @@ module NotionRubyMapping
80
80
 
81
81
  # @return [Boolean]
82
82
  def is_inline
83
- self["is_inline"]
83
+ self[:is_inline]
84
84
  end
85
85
 
86
86
  # @param [Boolean] flag
@@ -107,7 +107,7 @@ module NotionRubyMapping
107
107
  Base.dry_run_script :post, @nc.query_database_path(@id), query.query_json
108
108
  else
109
109
  response = @nc.database_query_request @id, query
110
- List.new json: response, type: :database, value: self, query: query
110
+ List.new json: response, type: "database", value: self, query: query
111
111
  end
112
112
  end
113
113
 
@@ -13,7 +13,7 @@ module NotionRubyMapping
13
13
 
14
14
  # @return [String (frozen)]
15
15
  def type
16
- "divider"
16
+ :divider
17
17
  end
18
18
  end
19
19
  end