Class: Hikkmemo::Reader
- Inherits:
-
Object
- Object
- Hikkmemo::Reader
- Defined in:
- lib/hikkmemo/reader.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #doc(url) ⇒ Object
- #fringe ⇒ Object
-
#initialize(url, &block) ⇒ Reader
constructor
A new instance of Reader.
- #post_data(node, thread_id) ⇒ Object
- #thread_posts(thread_id, after: nil) ⇒ Object
Constructor Details
#initialize(url, &block) ⇒ Reader
Returns a new instance of Reader.
7 8 9 10 |
# File 'lib/hikkmemo/reader.rb', line 7 def initialize(url, &block) @url = url self.instance_eval(&block) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/hikkmemo/reader.rb', line 5 def url @url end |
Instance Method Details
#doc(url) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/hikkmemo/reader.rb', line 12 def doc(url) begin Nokogiri::HTML(open(url)) rescue puts "Failed accessing #{url}, retrying..." sleep 2 retry end end |
#fringe ⇒ Object
22 23 24 25 26 |
# File 'lib/hikkmemo/reader.rb', line 22 def fringe @threads.(doc(@url)).map do |t| [@thread_id.(t), @post_id.(@posts.(t).last)] end end |
#post_data(node, thread_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hikkmemo/reader.rb', line 33 def post_data(node, thread_id) { :id => @post_id.(node), :thread => thread_id, :date => @post_date.(node), :author => @post_author.(node), :subject => @post_subject.(node), :message => @post_message.(node), :image => @post_image.(node), :embed => @post_embed.(node) } end |
#thread_posts(thread_id, after: nil) ⇒ Object
28 29 30 31 |
# File 'lib/hikkmemo/reader.rb', line 28 def thread_posts(thread_id, after: nil) posts = @posts.(doc(@thread_url.(thread_id))) after ? posts.drop_while {|p| @post_id.(p) <= after } : posts end |