Class: NotionToMd::Blocks::Block
- Inherits:
-
Object
- Object
- NotionToMd::Blocks::Block
- Extended by:
- Forwardable
- Defined in:
- lib/notion_to_md/blocks/block.rb
Direct Known Subclasses
BulletedListBlock, BulletedListItemBlock, TableBlock, TableRowBlock
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
-
#initialize(block:, children: []) ⇒ Block
constructor
Parameters: block:: A Notion::Messages::Message object.
-
#to_md(tab_width: 0) ⇒ Object
Parameters: tab_width:: The number of tabs used to indent the block.
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
10 11 12 |
# File 'lib/notion_to_md/blocks/block.rb', line 10 def block @block end |
#children ⇒ Object (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 |