Class: Mona::Thread
- Inherits:
-
Object
- Object
- Mona::Thread
- Defined in:
- lib/mona/thread.rb
Overview
Thread of 2ch.net
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#dat_size ⇒ Object
readonly
Returns the value of attribute dat_size.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_accessed_at ⇒ Object
readonly
Returns the value of attribute last_accessed_at.
-
#res_num ⇒ Object
readonly
Returns the value of attribute res_num.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Thread
constructor
initialize method.
- #parse_body(body) ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Thread
initialize method
required options
- :board
-
instance of Board
- :id
-
thread id
optionals
- :title
-
title of thread
- :res_num
-
number of res
- :last_accessed_at
-
timestamp of last accessed time
- :dat_size
-
size of known dat file
22 23 24 25 26 27 28 29 |
# File 'lib/mona/thread.rb', line 22 def initialize(args = {}) @board = args[:board] @title = args[:title] @id = args[:id] @res_num = args[:res_num] @last_accessed_at = Time.at(args[:last_accessed_at] || 0) @dat_size = args[:dat_size] || 0 end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def board @board end |
#dat_size ⇒ Object (readonly)
Returns the value of attribute dat_size.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def dat_size @dat_size end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def id @id end |
#last_accessed_at ⇒ Object (readonly)
Returns the value of attribute last_accessed_at.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def last_accessed_at @last_accessed_at end |
#res_num ⇒ Object (readonly)
Returns the value of attribute res_num.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def res_num @res_num end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/mona/thread.rb', line 9 def title @title end |
Class Method Details
Instance Method Details
#parse_body(body) ⇒ Object
38 39 40 41 42 |
# File 'lib/mona/thread.rb', line 38 def parse_body(body) first = body.lines.first.strip.split(/<>/) @title = first[4] if first[4] body.lines.map{ |line| Mona::Response.parse_line(line) } end |
#reload ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mona/thread.rb', line 44 def reload headers = {'If-Modified-Since' => @last_accessed_at.rfc2822, 'Range' => @dat_size} res = Mona::Client.new.get(dat_url, :header => headers) case res.status when 200 @dat_size += res.body.bytesize @last_accessed_at = Time.rfc2822(res.header["Last-Modified"].first) body = res.body.toutf8 parse_body(body) end end |