Class: Reissue::Markdown::Header
- Inherits:
-
Object
- Object
- Reissue::Markdown::Header
- Defined in:
- lib/reissue/markdown.rb
Instance Method Summary collapse
-
#initialize(chunk) ⇒ Header
constructor
A new instance of Header.
- #parse ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(chunk) ⇒ Header
Returns a new instance of Header.
29 30 31 32 33 |
# File 'lib/reissue/markdown.rb', line 29 def initialize(chunk) @chunk = chunk.to_s @title = nil @preamble = nil end |
Instance Method Details
#parse ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/reissue/markdown.rb', line 35 def parse return unless @title.nil? && @preamble.nil? scanner = StringScanner.new(@chunk.dup << "\n") scanner.scan(/# ([\w\s]+)$/) @title = scanner[1].to_s.strip # the rest of the text is the preamble @preamble = scanner.rest.strip end |
#to_h ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/reissue/markdown.rb', line 45 def to_h parse { "title" => @title, "preamble" => @preamble } end |