Class: NotionOrbit::NotionObjects::Block
- Inherits:
-
Object
- Object
- NotionOrbit::NotionObjects::Block
show all
- Defined in:
- lib/notion_orbit/notion_objects/block.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw_block, notion_api_key, indentation) ⇒ Block
Returns a new instance of Block.
28
29
30
31
32
33
34
35
|
# File 'lib/notion_orbit/notion_objects/block.rb', line 28
def initialize(raw_block, notion_api_key, indentation)
@raw_block = raw_block
@id = raw_block.id
@type = raw_block.type
@has_children = raw_block.has_children
@indentation = indentation
@notion_api_key = notion_api_key
end
|
Class Method Details
.new_from_raw_block(raw_block, notion_api_key, indentation: 0) ⇒ Object
Instance Method Details
#indent_children? ⇒ Boolean
52
53
54
|
# File 'lib/notion_orbit/notion_objects/block.rb', line 52
def indent_children?
false
end
|
#notion_service ⇒ Object
56
57
58
|
# File 'lib/notion_orbit/notion_objects/block.rb', line 56
def notion_service
@notion_service ||= NotionOrbit::Services::Notion.new(notion_api_key: @notion_api_key)
end
|
#to_markdown ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/notion_orbit/notion_objects/block.rb', line 37
def to_markdown
markdown = @raw_block[@type].text.map do |rich_text|
NotionOrbit::NotionObjects::RichText.new(rich_text).to_markdown
end.join
if @has_children
raw_children = notion_service.client.block_children(id: @id).results
children_indentation = indent_children? ? @indentation + 2 : @indentation
children_blocks = Blocks.new(raw_children, @notion_api_key, indentation: children_indentation)
markdown += "\n\n" + children_blocks.to_markdown
end
markdown
end
|