Class: NotionToMd::Blocks::Builder
- Inherits:
-
Object
- Object
- NotionToMd::Blocks::Builder
- Defined in:
- lib/notion_to_md/blocks/builder.rb
Constant Summary collapse
- BLOCKS_WITH_PERMITTED_CHILDREN =
Array containing the block types allowed to have nested blocks (children).
%i[ bulleted_list_item numbered_list_item paragraph to_do table ].freeze
Instance Attribute Summary collapse
-
#block_id ⇒ Object
readonly
Returns the value of attribute block_id.
-
#fetch_blocks ⇒ Object
readonly
Returns the value of attribute fetch_blocks.
Class Method Summary collapse
-
.permitted_children_for?(block:) ⇒ Boolean
Parameters block:: A Notion::Messages::Message object.
Instance Method Summary collapse
-
#build ⇒ Object
Parameters.
-
#initialize(block_id:, &fetch_blocks) ⇒ Builder
constructor
Parameters block_id:: A string representing a notion block id .
Constructor Details
#initialize(block_id:, &fetch_blocks) ⇒ Builder
Parameters
- block_id
-
A string representing a notion block id .
- fetch_blocks
-
A block that fetches the blocks from the Notion API.
Returns
An array of NotionToMd::Blocks::Block.
39 40 41 42 |
# File 'lib/notion_to_md/blocks/builder.rb', line 39 def initialize(block_id:, &fetch_blocks) @block_id = block_id @fetch_blocks = fetch_blocks end |
Instance Attribute Details
#block_id ⇒ Object (readonly)
Returns the value of attribute block_id.
28 29 30 |
# File 'lib/notion_to_md/blocks/builder.rb', line 28 def block_id @block_id end |
#fetch_blocks ⇒ Object (readonly)
Returns the value of attribute fetch_blocks.
28 29 30 |
# File 'lib/notion_to_md/blocks/builder.rb', line 28 def fetch_blocks @fetch_blocks end |
Class Method Details
.permitted_children_for?(block:) ⇒ Boolean
Parameters
- block
-
A Notion::Messages::Message object.
Returns
A boolean indicating if the blocked passed in is permitted to have children based on its type.
24 25 26 |
# File 'lib/notion_to_md/blocks/builder.rb', line 24 def self.permitted_children_for?(block:) BLOCKS_WITH_PERMITTED_CHILDREN.include?(block.type.to_sym) && block.has_children end |
Instance Method Details
#build ⇒ Object
Parameters
Returns
An array of NotionToMd::Blocks::Block.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/notion_to_md/blocks/builder.rb', line 49 def build = fetch_blocks.call(block_id) blocks = .results.map do |block| children = if Builder.permitted_children_for?(block: block) Builder.new(block_id: block.id, &fetch_blocks).build else [] end Factory.build(block: block, children: children) end Normalizer.normalize(blocks: blocks) end |