Skip to content

Instantly share code, notes, and snippets.

/model Secret

Created May 19, 2016 19:56
Show Gist options
  • Save anonymous/ff9e556487ecf88a53e062d2fbea68d6 to your computer and use it in GitHub Desktop.
Save anonymous/ff9e556487ecf88a53e062d2fbea68d6 to your computer and use it in GitHub Desktop.
class Post
@@posts ||= []
attr_accessor :body, :header
def initialize (doc, slug)
self.header, self.body = doc.split("\n...\n")
self.header = YAML.load(header)
self.header['slug'] = slug + '.html'
@@posts << self
end
def all
@@posts
end
end
def collect_files_from(dir)
files = Dir[dir+'*.text']
files.each do |file|
slug = File.basename(file, ".text")
file = File.read(file)
return Post.new(file, slug)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment