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_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
61 62 63 |
# File 'app/models/page_set.rb', line 61 def self.inject([]) { |, page| << page. }.flatten.uniq.sort 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
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_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
53 54 55 |
# File 'app/models/page_set.rb', line 53 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
42 43 44 45 |
# File 'app/models/page_set.rb', line 42 def orphaned_pages references = web.select.wiki_words + ["HomePage"] + web.select. 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 () self.select { |page| page..include?() } 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_pages ⇒ Object
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_words ⇒ Object
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 |