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



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

def authors
  self.inject([]) { |authors, page| authors << page.authors }.flatten.uniq.sort
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



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

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



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

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



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

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



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

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

#pages_that_reference(page_name) ⇒ Object



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

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



49
50
51
# File 'app/models/page_set.rb', line 49

def wanted_pages
  wiki_words - web.select.names
end

#wiki_wordsObject



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

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