class Directory

Public Class Methods

new(path) click to toggle source
# File lib/abelard/dir.rb, line 68
def initialize(path)
  @path = path
  @base_doc = read_base_doc
  @feed_type = case @base_doc.root.name
               when "feed"
                 :atom
               when "rss"
                 :rss
               else
                 :unknown
               end

  @git = History.new(self, path)
end

Public Instance Methods

base_doc() click to toggle source
# File lib/abelard/dir.rb, line 96
def base_doc
  if ! @base_doc
    @base_doc = read_base_doc
  end
  @base_doc
end
each() { |by_date| ... } click to toggle source

iterates the Item objects for the feed, in order

# File lib/abelard/dir.rb, line 104
def each
  by_date = {}
  each_unsorted do |post,filename|
    item = Item.new(post,filename)
    by_date[item.timestamp] = item
  end
  by_date.keys.sort.map { |dt| yield by_date[dt] }
end
each_unsorted() { |post, filename| ... } click to toggle source
# File lib/abelard/dir.rb, line 139
def each_unsorted
  Dir.glob("#{@path}/post-*.xml") do |filename|
    post = LibXML::XML::Parser.file(filename).parse
    yield post, filename
  end
end
info() click to toggle source
# File lib/abelard/dir.rb, line 113
def info
  inf = {}
  el = base_doc.find_first("/atom:feed/atom:title", NS) ||
       base_doc.find_first("/rss/channel/title")
  inf["title"] = el.content
  inf
end
insert_posts(collection) click to toggle source
# File lib/abelard/dir.rb, line 131
def insert_posts(collection)
  each do |post|
    $stderr.puts "adding #{post.file}"
    collection << collection.doc.import(post.doc.root)
  end
  collection
end
posts_feed() click to toggle source
# File lib/abelard/dir.rb, line 121
def posts_feed
  feed = read_base_doc
  case @feed_type
  when :atom
    posts_feed_atom(feed)
  when :rss
    posts_feed_rss(feed)
  end
end
posts_feed_atom(doc) click to toggle source
# File lib/abelard/dir.rb, line 146
def posts_feed_atom(doc)
  insert_posts(doc.root)
  doc
end
posts_feed_rss(rssdoc) click to toggle source
# File lib/abelard/dir.rb, line 151
def posts_feed_rss(rssdoc)
  doc = LibXML::XML::Parser.file("#{@path}/channel-1.xml").parse
  channel = doc.find_first("/rss/channel");
  insert_posts(channel)
  doc
end
read_base_doc() click to toggle source
# File lib/abelard/dir.rb, line 87
def read_base_doc
  feed = LibXML::XML::Parser.file("#{@path}/feed.xml").parse
  if feed.root.name == "rss"
    LibXML::XML::Parser.file("#{@path}/channel-1.xml").parse
  else
    feed
  end
end
save() click to toggle source
# File lib/abelard/dir.rb, line 83
def save
  @git.commit_posts
end
sort_entries(repo_entries) click to toggle source
# File lib/abelard/dir.rb, line 158
def sort_entries(repo_entries)
  by_date = repo_entries.map do |e|
    { :entry => e,
      :time => Item.new(LibXML::XML::Parser.file(e.path).parse, e.path ).timestamp }
  end
  by_date.sort! { |a,b| a[:time] <=> b[:time] }
  by_date.map { |hash| hash[:entry] }
end