Sha256: ef983edf14dd77fd88d8a3c2e2fb00276d9188bb4a88ba374d16532dec34dea8
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
# Container for a set of pages with methods for manipulation. class PageSet < Array attr_reader :web def initialize(web, pages, accept_proc) @web = web if accept_proc.nil? then super(pages) else super(pages.select { |page| accept_proc[page] }) end end def most_recent_revision self.sort_by { |page| [page.created_at] }.reverse.first.created_at end def by_name self.sort_by { |page| [page.name] } end def by_revision self.sort_by { |page| [page.created_at] }.reverse end def by_last_visited #{{{ self.sort_by { |page| [page.last_visited] }.reverse end #}}} def by_most_viewed #{{{ self.sort_by { |page| [page.viewed] }.reverse end #}}} def pages_that_reference(page_name) self.select { |page| page.wiki_words.include?(page_name) } end def pages_authored_by(author) self.select { |page| page.authors.include?(author) } end def characters self.inject(0) { |chars,page| chars += page.content.size } end # Returns all the orphaned pages in this page set. That is, # pages in this set for which there is no reference in the web. # The HomePage and author pages are always assumed to have # references and so cannot be orphans def orphaned_pages references = web.select.wiki_words + ["HomePage"] + web.select.authors self.reject { |page| references.include?(page.name) } end # Returns all the wiki words in this page set for which # there are no pages in this page set's web def wanted_pages wiki_words - web.select.names end def names self.map { |page| page.name } end def wiki_words self.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq end def authors self.inject([]) { |authors, page| authors << page.authors }.flatten.uniq.sort end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
Pimki-1.2.092 | app/models/page_set.rb |
Pimki-1.0.092 | app/models/page_set.rb |
Pimki-1.1.092 | app/models/page_set.rb |
Pimki-1.3.092 | app/models/page_set.rb |