Permalink
Browse files

Added voting_on property on poll. All properties finished.

Now I need to do some testing and write sth to put HN into a DB!
  • Loading branch information...
1 parent f4ab13a commit db6a48a4da492df0fe1854483f28583b187ec1d6 @jcla1 committed Oct 7, 2012
Showing with 19 additions and 5 deletions.
  1. +18 −4 lib/hn2json/parser.rb
  2. +1 −1 lib/hn2json/version.rb
View
@@ -123,14 +123,16 @@ def get_attrs_poll entity
fulltext = ''
end
+ voting_on = get_voting_on
+
entity.add_attrs do |e|
e.title = title
e.fulltext = fulltext
e.date_posted = date_posted
e.posted_by = posted_by
e.votes = votes
e.comments = comments
- #e.voting_on = voting_on
+ e.voting_on = voting_on
end
end
@@ -161,9 +163,21 @@ def get_attrs_discussion entity
end
- def get_voting_on table
- fulltext = ''
- voting_on = ''
+ def get_voting_on
+ voting_on = []
+ trs = @doc.css('tr > td + td > table tr')
+
+ trs.each_with_index do |tr, index|
+ if index % 3 == 0
+ voting_on.push []
+ voting_on[(index / 3).floor].push tr.content
+ elsif index % 3 == 1
+ voting_on[(index / 3).floor].push tr.content.gsub(/\spoints/, '')
+ end
+ end
+
+ return voting_on
+
end
def get_comments
View
@@ -1,3 +1,3 @@
module HN2JSON
- VERSION = '0.0.3'
+ VERSION = '0.0.4'
end

0 comments on commit db6a48a

Please sign in to comment.