class NotionOrbit::NotionObjects::RichText

Public Class Methods

new(raw_rich_text) click to toggle source
# File lib/notion_orbit/notion_objects/rich_text.rb, line 4
def initialize(raw_rich_text)
  @raw_rich_text = raw_rich_text
  @type = raw_rich_text.type
  @annotations = raw_rich_text.annotations
  @text = raw_rich_text.text
end

Public Instance Methods

apply_annotations(content) click to toggle source
# File lib/notion_orbit/notion_objects/rich_text.rb, line 23
def apply_annotations(content)
  annotation_symbols = []
  annotation_symbols << '**' if @annotations.bold
  annotation_symbols << '_' if @annotations.italic
  annotation_symbols << '`' if @annotations.code
  wrap_with(content, annotation_symbols)
end
to_markdown() click to toggle source
# File lib/notion_orbit/notion_objects/rich_text.rb, line 11
def to_markdown
  return "" unless @type == 'text'
  markdown = @text.content
  markdown = apply_link(markdown) unless @text.link.nil?
  markdown = apply_annotations(markdown)
  markdown
end
wrap_with(string, wrappers) click to toggle source
# File lib/notion_orbit/notion_objects/rich_text.rb, line 31
def wrap_with(string, wrappers)
  "#{wrappers.join}#{string}#{wrappers.reverse.join}"
end