Class: Fourchan
- Inherits:
-
Object
- Object
- Fourchan
- Defined in:
- lib/four-chan.rb
Overview
Everything else should be methods that extract stuff from data
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#addPage(page) ⇒ Object
The format of page must be the same as one of the elements in the pages argument in the initialization function(2-element array containing symbol denoting board and enumerable denoting pages).
-
#initialize(pages) ⇒ Fourchan
constructor
and an array containing the numbers of the pages to be pulled.
-
#postsText(board, page) ⇒ Object
Returns an array, each element being the text from one post on the given page.
-
#reset ⇒ Object
Resets all page data in the current object, pulling it from the web anew.
Constructor Details
#initialize(pages) ⇒ Fourchan
and an array containing the numbers of the pages to be pulled
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/four-chan.rb', line 14 def initialize(pages) @pages = pages @data = Hash[] for i in pages board = i[0] for j in i[1] key = [board, j] path = "http://boards.4chan.org/" + board.to_s + "/" + j doc = Nokogiri::Doc.new(open(path)) @data[key] = doc end end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
61 62 63 |
# File 'lib/four-chan.rb', line 61 def data @data end |
Instance Method Details
#addPage(page) ⇒ Object
The format of page must be the same as one of the elements in the pages argument in the initialization function(2-element array containing symbol denoting board and enumerable denoting pages)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/four-chan.rb', line 33 def addPage(page) found = false for i in @pages if i[0] == page[0] i[1] = (i[1] + page[1]).uniq found = true break end end @pages += page unless found board = page[0] for i in page[1] key = [board, i] path = "http://boards.4chan.org/" + board.to_s + "/" + i doc = Nokogiri::Doc.new(open(path)) @data[key] = doc end end |
#postsText(board, page) ⇒ Object
Returns an array, each element being the text from one post on the given page
52 53 54 55 56 57 58 59 60 |
# File 'lib/four-chan.rb', line 52 def postsText(board, page) key = [board, page] doc = @data[key] raw = doc.xpath("//blockquote") raw.delete do |a| not (a["class"].include? "post") end raw end |