Class: PageSet
- Inherits:
-
Array
- Object
- Array
- PageSet
- Defined in:
- app/models/page_set.rb
Overview
Container for a set of pages with methods for manipulation.
Instance Attribute Summary collapse
-
#web ⇒ Object
readonly
Returns the value of attribute web.
Instance Method Summary collapse
- #authors ⇒ Object
-
#by_last_visited ⇒ Object
{{{.
-
#by_most_viewed ⇒ Object
}}}.
- #by_name ⇒ Object
- #by_revision ⇒ Object
- #characters ⇒ Object
-
#initialize(web, pages, accept_proc) ⇒ PageSet
constructor
A new instance of PageSet.
- #most_recent_revision ⇒ Object
- #names ⇒ Object
-
#orphaned_pages ⇒ Object
Returns all the orphaned pages in this page set.
- #pages_authored_by(author) ⇒ Object
- #pages_that_reference(page_name) ⇒ Object
-
#wanted_pages ⇒ Object
Returns all the wiki words in this page set for which there are no pages in this page set’s web.
- #wiki_words ⇒ Object
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
#web ⇒ Object (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
#authors ⇒ Object
70 71 72 |
# File 'app/models/page_set.rb', line 70 def self.inject([]) { |, page| << page. }.flatten.uniq.sort end |
#by_last_visited ⇒ Object
{{{
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_viewed ⇒ Object
}}}
30 31 32 |
# File 'app/models/page_set.rb', line 30 def by_most_viewed #{{{ self.sort_by { |page| [page.viewed] }.reverse end |
#by_name ⇒ Object
18 19 20 |
# File 'app/models/page_set.rb', line 18 def by_name self.sort_by { |page| [page.name] } end |
#by_revision ⇒ Object
22 23 24 |
# File 'app/models/page_set.rb', line 22 def by_revision self.sort_by { |page| [page.created_at] }.reverse end |
#characters ⇒ Object
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_revision ⇒ Object
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 |
#names ⇒ Object
62 63 64 |
# File 'app/models/page_set.rb', line 62 def names self.map { |page| page.name } end |
#orphaned_pages ⇒ Object
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. 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 () self.select { |page| page..include?() } 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_pages ⇒ Object
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_words ⇒ Object
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 |