Class: HackerNews::Item
- Inherits:
-
Object
- Object
- HackerNews::Item
- Defined in:
- lib/hacker_news/item.rb
Instance Attribute Summary collapse
-
#comments_count ⇒ Object
Returns the value of attribute comments_count.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#item_id ⇒ Object
Returns the value of attribute item_id.
-
#points ⇒ Object
Returns the value of attribute points.
-
#position ⇒ Object
Returns the value of attribute position.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #comments ⇒ Object
-
#initialize(node, position) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(node, position) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hacker_news/item.rb', line 7 def initialize(node, position) tr = node.parent.parent points_comments_tr = tr.next points_comments_td = points_comments_tr.css("td.subtext")[0] #@title = Iconv.iconv('iso-8859-1//translit', 'utf-8', node.text)[0].to_s.strip @title = Iconv.iconv('iso-8859-1//IGNORE', 'US-ASCII', node.text)[0].to_s.strip @url = node[:href] @position = position @points = points_comments_td.css("span")[0].text.to_i rescue nil @item_id = points_comments_td.css("span")[0][:id].split("_")[1].to_i rescue nil @user = points_comments_td.css("a")[0].text.strip rescue nil @comments_count = points_comments_td.css("a")[1].text.to_i rescue 0 @created_at = points_comments_tr.text.match(/by [-\w]+ (.*) \|/)[1].strip rescue nil @created_at ||= points_comments_tr.text end |
Instance Attribute Details
#comments_count ⇒ Object
Returns the value of attribute comments_count.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def comments_count @comments_count end |
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def created_at @created_at end |
#item_id ⇒ Object
Returns the value of attribute item_id.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def item_id @item_id end |
#points ⇒ Object
Returns the value of attribute points.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def points @points end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def position @position end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/hacker_news/item.rb', line 5 def user @user end |