Class: PageSet

Inherits:
Array
  • Object
show all
Defined in:
app/models/page_set.rb

Overview

Container for a set of pages with methods for manipulation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(web, pages, accept_proc) ⇒ PageSet

Returns a new instance of PageSet.



5
6
7
8
9
10
11
12
# File 'app/models/page_set.rb', line 5

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

Instance Attribute Details

#webObject (readonly)

Returns the value of attribute web.



3
4
5
# File 'app/models/page_set.rb', line 3

def web
  @web
end

Instance Method Details

#authorsObject



70
71
72
# File 'app/models/page_set.rb', line 70

def authors
  self.inject([]) { |authors, page| authors << page.authors }.flatten.uniq.sort
end

#by_last_visitedObject

{{{



26
27
28
# File 'app/models/page_set.rb', line 26

def by_last_visited #{{{
  self.sort_by { |page| [page.last_visited] }.reverse
end

#by_most_viewedObject

}}}



30
31
32
# File 'app/models/page_set.rb', line 30

def by_most_viewed #{{{
  self.sort_by { |page| [page.viewed] }.reverse
end

#by_nameObject



18
19
20
# File 'app/models/page_set.rb', line 18

def by_name
  self.sort_by { |page| [page.name] } 
end

#by_revisionObject



22
23
24
# File 'app/models/page_set.rb', line 22

def by_revision
  self.sort_by { |page| [page.created_at] }.reverse 
end

#charactersObject



43
44
45
# File 'app/models/page_set.rb', line 43

def characters
  self.inject(0) { |chars,page| chars += page.content.size }
end

#most_recent_revisionObject



14
15
16
# File 'app/models/page_set.rb', line 14

def most_recent_revision
  self.sort_by { |page| [page.created_at] }.reverse.first.created_at
end

#namesObject



62
63
64
# File 'app/models/page_set.rb', line 62

def names
  self.map { |page| page.name }
end

#orphaned_pagesObject

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



51
52
53
54
# File 'app/models/page_set.rb', line 51

def orphaned_pages
  references = web.select.wiki_words + ["HomePage"] + web.select.authors
  self.reject { |page| references.include?(page.name) } 
end

#pages_authored_by(author) ⇒ Object



39
40
41
# File 'app/models/page_set.rb', line 39

def pages_authored_by(author)
  self.select { |page| page.authors.include?(author) }
end

#pages_that_reference(page_name) ⇒ Object



35
36
37
# File 'app/models/page_set.rb', line 35

def pages_that_reference(page_name)
  self.select { |page| page.wiki_words.include?(page_name) }
end

#wanted_pagesObject

Returns all the wiki words in this page set for which there are no pages in this page set’s web



58
59
60
# File 'app/models/page_set.rb', line 58

def wanted_pages
  wiki_words - web.select.names
end

#wiki_wordsObject



66
67
68
# File 'app/models/page_set.rb', line 66

def wiki_words
  self.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq
end