Class: Hellm::MarkdownFile

Inherits:
Object
  • Object
show all
Defined in:
lib/hellm/markdown_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/hellm/markdown_file.rb', line 4

def attributes
  @attributes
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/hellm/markdown_file.rb', line 4

def content
  @content
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/hellm/markdown_file.rb', line 4

def path
  @path
end

Class Method Details

.read(path) ⇒ Object



6
7
8
9
10
# File 'lib/hellm/markdown_file.rb', line 6

def self.read(path)
  file = new(path)
  file.read
  file
end

Instance Method Details

#fetch(key, default = nil) ⇒ Object



12
13
14
# File 'lib/hellm/markdown_file.rb', line 12

def fetch(key, default=nil)
  attributes.fetch(key.to_s, default)
end

#readObject



16
17
18
19
20
21
22
23
# File 'lib/hellm/markdown_file.rb', line 16

def read
  file = File.read(path)
  frontmatter, content = separate_frontmatter_and_content(file)
  self.attributes = YAML.load(frontmatter) if frontmatter != ""
  self.attributes ||= {}
  self.content = content
  self
end