Class: NotionRubyMapping::CodeBlock

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

Overview

Notion block

Instance Attribute Summary collapse

Attributes inherited from Block

#can_append, #can_have_children, #color, #url

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(text_info = nil, caption: [], language: "shell", json: nil, id: nil, parent: nil) ⇒ CodeBlock

Returns a new instance of CodeBlock.

Parameters:

See Also:



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

def initialize(text_info = nil, caption: [], language: "shell", json: nil, id: nil, parent: nil)
  super(json: json, id: id, parent: parent)
  if @json
    decode_block_rich_text_array
    decode_block_caption
    @language = json[type]["language"] || "shell"
  else
    rich_text_array_and_color "rich_text", text_info
    @caption = RichTextArray.rich_text_array "caption", caption
    @language = language
  end
end

Instance Attribute Details

#captionObject (readonly)



26
27
28
# File 'lib/notion_ruby_mapping/blocks/code_block.rb', line 26

def caption
  @caption
end

#languageObject



26
27
28
# File 'lib/notion_ruby_mapping/blocks/code_block.rb', line 26

def language
  @language
end

#rich_text_arrayObject (readonly)



26
27
28
# File 'lib/notion_ruby_mapping/blocks/code_block.rb', line 26

def rich_text_array
  @rich_text_array
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)

    ]



30
31
32
33
34
35
36
37
# File 'lib/notion_ruby_mapping/blocks/code_block.rb', line 30

def block_json(not_update: true)
  ans = super
  ans[type] = @rich_text_array.update_property_schema_json(not_update).merge(
    @caption.update_property_schema_json(not_update),
  )
  ans[type]["language"] = @language
  ans
end

#typeString

Returns:

  • (String)


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

def type
  "code"
end