Class: MdRecord::FrontmatterParser

Inherits:
Object
  • Object
show all
Defined in:
lib/md_record/frontmatter_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject (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

#frontmatterObject (readonly)

Returns the value of attribute frontmatter.



7
8
9
# File 'lib/md_record/frontmatter_parser.rb', line 7

def frontmatter
  @frontmatter
end

#markdown_contentObject (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

#contentObject



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

#publishedObject



26
27
28
# File 'lib/md_record/frontmatter_parser.rb', line 26

def published
  frontmatter.fetch("published", false)
end

#slugObject



14
15
16
# File 'lib/md_record/frontmatter_parser.rb', line 14

def slug
  File.basename(file_path, ".md")
end

#titleObject



18
19
20
# File 'lib/md_record/frontmatter_parser.rb', line 18

def title
  frontmatter.fetch("title", slug.titleize)
end