Class: NotionRubyMapping::FileBaseBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/notion_ruby_mapping/blocks/file_base_block.rb

Overview

Notion block

Direct Known Subclasses

FileBlock, ImageBlock, PdfBlock, VideoBlock

Instance Attribute Summary collapse

Attributes inherited from Block

#can_append, #can_have_children, #color, #language, #rich_text_array, #type

Attributes inherited from Base

#archived, #has_children, #id, #json

Instance Method Summary collapse

Methods inherited from Block

#append_after, #children_block_json, decode_block, #decode_block_caption, #decode_block_rich_text_array, #decode_color, #destroy, find, type2class, #update, #update_block_json

Methods inherited from Base

#append_block_children, #assert_parent_children_pair, #assign_property, #block?, block_id, #children, #comments, #cover, create_from_json, #created_time, #database?, database_id, dry_run_script, #get, #icon, #inspect, #json_properties, #last_edited_time, #new_record?, #page?, page_id, #parent, #parent_id, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_cover, #set_icon, #synced_block_original?, #update_json

Constructor Details

#initialize(url = nil, caption: [], json: nil, id: nil, parent: nil) ⇒ FileBaseBlock

Returns a new instance of FileBaseBlock.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 10

def initialize(url = nil, caption: [], json: nil, id: nil, parent: nil)
  super(json: json, id: id, parent: parent)
  if @json
    @file_object = FileObject.new json: @json[type]
    decode_block_caption
    @can_append = @file_object.external?
  else
    @file_object = FileObject.file_object url
    @caption = RichTextArray.rich_text_array "caption", caption
  end
end

Instance Attribute Details

#captionObject (readonly)



24
25
26
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 24

def caption
  @caption
end

#file_objectObject (readonly)



24
25
26
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 24

def file_object
  @file_object
end

Instance Method Details

#block_json(not_update: true) ⇒ Hash{String (frozen)->Hash

Returns ].

Parameters:

  • not_update (Boolean) (defaults to: true)

    false when update

Returns:

  • (Hash{String (frozen)->Hash)

    ]



28
29
30
31
32
33
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 28

def block_json(not_update: true)
  ans = super
  ans[type] = @file_object.property_values_json
  ans[type].merge! @caption.update_property_schema_json(not_update) if @caption
  ans
end

#file_upload_object=(fuo) ⇒ Object

Parameters:



51
52
53
54
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 51

def file_upload_object=(fuo)
  @file_object.file_upload_object = fuo
  @payload.add_update_block_key "file_upload"
end

#update_file_object_from_json(json) ⇒ Object



56
57
58
59
60
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 56

def update_file_object_from_json(json)
  @file_object = FileObject.new json: json[type]
  decode_block_caption
  @can_append = @file_object.external?
end

#urlString



38
39
40
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 38

def url
  @file_object&.url
end

#url=(url) ⇒ Object



45
46
47
48
# File 'lib/notion_ruby_mapping/blocks/file_base_block.rb', line 45

def url=(url)
  @file_object.url = url
  @payload.add_update_block_key "external"
end