Class: NotionToMd::Blocks::Block

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/notion_to_md/blocks/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block:, children: []) ⇒ Block

Parameters:

block

A Notion::Messages::Message object.

children

An array of NotionToMd::Block::Block objects.

Returns

A Block object.



23
24
25
26
# File 'lib/notion_to_md/blocks/block.rb', line 23

def initialize(block:, children: [])
  @block = block
  @children = children
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



10
11
12
# File 'lib/notion_to_md/blocks/block.rb', line 10

def block
  @block
end

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/notion_to_md/blocks/block.rb', line 10

def children
  @children
end

Instance Method Details

#to_md(tab_width: 0) ⇒ Object

Parameters:

tab_width

The number of tabs used to indent the block.

Returns

The current block (and its children) converted to a markdown string.



35
36
37
38
39
40
41
42
# File 'lib/notion_to_md/blocks/block.rb', line 35

def to_md(tab_width: 0)
  block_type = block.type.to_sym
  md = Types.send(block_type, block[block_type]) + newline
  md + build_nested_blocks(tab_width + 1)
rescue NoMethodError
  Logger.info("Unsupported block type: #{block_type}")
  nil
end