Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created August 6, 2008 05:31
Show Gist options
  • Save practicingruby/4174 to your computer and use it in GitHub Desktop.
Save practicingruby/4174 to your computer and use it in GitHub Desktop.
class Entry
def self.registry
@registry ||= YAML.load_file("#{Blaag::BASEDIR}/data/registry.yml")
end
def self.update_registry(filename,mtime)
registry[filename] ||= mtime
File.open("#{Blaag::BASEDIR}/data/registry.yml","w") do |f|
f << @registry.to_yaml
end
end
def self.load(filename)
file = File.open(filename)
update_registry(filename,file.mtime)
options = parse(file.read)
options[:published_date] = registry[filename]
options[:archive] =
File.dirname(filename) =~ /.*\/(.*)\/?.*/ && $1
options[:url] = "http://#{Blaag::DOMAIN}/archives/" +
"#{options[:archive]}/#{File.basename(filename)}.html"
options[:file] = File.basename(filename)
entry = Entry.new(options)
end
def self.parse(entry)
entry =~ /=title(.*)=description(.*)=entry(.*)/m
{ :title => $1.strip, :description => $2.strip, :entry => $3.strip }
end
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment