Class: Pic2ch::Parsers::Thread
- Inherits:
-
Object
- Object
- Pic2ch::Parsers::Thread
- Defined in:
- lib/pic2ch/parsers/thread.rb
Instance Method Summary collapse
- #count ⇒ Object
- #deleted? ⇒ Boolean
- #doc ⇒ Object
- #html ⇒ Object
- #images ⇒ Object
- #images_with_thumbs ⇒ Object
-
#initialize(thread) ⇒ Thread
constructor
A new instance of Thread.
- #jpgs ⇒ Object
- #thumbs ⇒ Object
- #time ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(thread) ⇒ Thread
Returns a new instance of Thread.
7 8 9 |
# File 'lib/pic2ch/parsers/thread.rb', line 7 def initialize(thread) @thread = thread end |
Instance Method Details
#count ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/pic2ch/parsers/thread.rb', line 26 def count unless @count check_deleted count = doc.css('h2').text.scan(/\((\d+)\)$/).flatten.first.to_s raise NotFound, "count" if count.empty? @count = count.to_i end return @count end |
#deleted? ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/pic2ch/parsers/thread.rb', line 19 def deleted? check_deleted return false rescue DeletedPage return true end |
#doc ⇒ Object
15 16 17 |
# File 'lib/pic2ch/parsers/thread.rb', line 15 def doc @doc ||= Nokogiri::HTML(html) end |
#html ⇒ Object
11 12 13 |
# File 'lib/pic2ch/parsers/thread.rb', line 11 def html @html ||= open(url).read{} end |
#images ⇒ Object
58 59 60 |
# File 'lib/pic2ch/parsers/thread.rb', line 58 def images @images ||= jpgs.map{|jpg| image_url + "/pics3/#{time}/#{jpg}" } end |
#images_with_thumbs ⇒ Object
62 63 64 |
# File 'lib/pic2ch/parsers/thread.rb', line 62 def images_with_thumbs @images_with_thumbs ||= [images, thumbs].transpose end |
#jpgs ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/pic2ch/parsers/thread.rb', line 36 def jpgs unless @jpgs check_deleted urls = extract(:urls).split(/:/) raise ParseError, "expected #{count} urls exist, but got #{urls.size}" unless urls.size == count @jpgs = urls end return @jpgs end |
#thumbs ⇒ Object
54 55 56 |
# File 'lib/pic2ch/parsers/thread.rb', line 54 def thumbs @thumbs ||= jpgs.map{|jpg| image_url + "/thumbs/#{time}/#{jpg}" } end |
#time ⇒ Object
46 47 48 |
# File 'lib/pic2ch/parsers/thread.rb', line 46 def time @time ||= extract(:id).to_i end |
#title ⇒ Object
50 51 52 |
# File 'lib/pic2ch/parsers/thread.rb', line 50 def title @title ||= doc.search("title").text end |