Class: MdRecord::FrontmatterParser
- Inherits:
-
Object
- Object
- MdRecord::FrontmatterParser
- Defined in:
- lib/md_record/frontmatter_parser.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#frontmatter ⇒ Object
readonly
Returns the value of attribute frontmatter.
-
#markdown_content ⇒ Object
readonly
Returns the value of attribute markdown_content.
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(file_path) ⇒ FrontmatterParser
constructor
A new instance of FrontmatterParser.
- #parse! ⇒ Object
- #published ⇒ Object
- #slug ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(file_path) ⇒ FrontmatterParser
Returns a new instance of FrontmatterParser.
9 10 11 12 |
# File 'lib/md_record/frontmatter_parser.rb', line 9 def initialize(file_path) @file_path = file_path @frontmatter = {} end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/md_record/frontmatter_parser.rb', line 7 def file_path @file_path end |
#frontmatter ⇒ Object (readonly)
Returns the value of attribute frontmatter.
7 8 9 |
# File 'lib/md_record/frontmatter_parser.rb', line 7 def frontmatter @frontmatter end |
#markdown_content ⇒ Object (readonly)
Returns the value of attribute markdown_content.
7 8 9 |
# File 'lib/md_record/frontmatter_parser.rb', line 7 def markdown_content @markdown_content end |
Instance Method Details
#content ⇒ Object
22 23 24 |
# File 'lib/md_record/frontmatter_parser.rb', line 22 def content markdown_content || raw_content end |
#parse! ⇒ Object
30 31 32 33 |
# File 'lib/md_record/frontmatter_parser.rb', line 30 def parse! parse_frontmatter! self end |
#published ⇒ Object
26 27 28 |
# File 'lib/md_record/frontmatter_parser.rb', line 26 def published frontmatter.fetch("published", false) end |
#slug ⇒ Object
14 15 16 |
# File 'lib/md_record/frontmatter_parser.rb', line 14 def slug File.basename(file_path, ".md") end |
#title ⇒ Object
18 19 20 |
# File 'lib/md_record/frontmatter_parser.rb', line 18 def title frontmatter.fetch("title", slug.titleize) end |