Class: Notion::Blocks::Builder
- Inherits:
-
Object
- Object
- Notion::Blocks::Builder
- Defined in:
- lib/notion/blocks/builder.rb
Constant Summary collapse
- ANNOTATIONS =
%i[bold italic strikethrough underline code color].freeze
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #method_missing(type, content = nil, **options, &block) ⇒ Object
- #respond_to_missing?(_name, _include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
10 11 12 |
# File 'lib/notion/blocks/builder.rb', line 10 def initialize @blocks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(type, content = nil, **options, &block) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/notion/blocks/builder.rb', line 14 def method_missing(type, content = nil, **, &block) children = self.class.build(&block) if block annotations = .slice(*ANNOTATIONS) payload = .except(*ANNOTATIONS).merge("rich_text" => rich_text(content, annotations)) payload["children"] = children if children @blocks << { "object" => "block", "type" => type.to_s, type.to_s => payload.compact } self end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
8 9 10 |
# File 'lib/notion/blocks/builder.rb', line 8 def blocks @blocks end |
Class Method Details
.build ⇒ Object
25 26 27 28 29 |
# File 'lib/notion/blocks/builder.rb', line 25 def self.build(&) builder = new builder.instance_eval(&) builder.blocks end |
Instance Method Details
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
23 |
# File 'lib/notion/blocks/builder.rb', line 23 def respond_to_missing?(_name, _include_private = false) = true |