Class: Sitepress::Parsers::Notion
- Defined in:
- lib/sitepress/parsers/notion.rb
Overview
Parses metadata from the header of the page.
Constant Summary collapse
- DELIMITER =
/\n\n/.freeze
- TITLE_KEY =
"Title".freeze
- KEY_DELIMITER =
":".freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(content) ⇒ Notion
constructor
A new instance of Notion.
Constructor Details
#initialize(content) ⇒ Notion
Returns a new instance of Notion.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sitepress/parsers/notion.rb', line 11 def initialize(content) scanner = StringScanner.new(content) # Parse title scanner.scan(/# (.+)#{DELIMITER}/) @title = scanner.captures.first # Parse metadata @raw_data = [] while scanner.scan(/(.+?)#{KEY_DELIMITER} (.+)\n/) @raw_data.append scanner.captures end scanner.scan(/\n/) # Parse body @body = scanner.rest end |
Instance Method Details
#data ⇒ Object
26 27 28 |
# File 'lib/sitepress/parsers/notion.rb', line 26 def data Hash[@raw_data.prepend([TITLE_KEY, @title])] end |