hnposts 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68d893f1165efc23bf5d3dbbb500f7c05d1d6242
4
- data.tar.gz: 13ad6bb3a4f43719afd3402be0f5c997ba7d68bc
3
+ metadata.gz: e82d7afe6c2a5c9fc820bb04b2b052a946f638b7
4
+ data.tar.gz: 298908d01dc037d5a236d310edb4ae60d34822ec
5
5
  SHA512:
6
- metadata.gz: 6c743222b23fc961008efcffae37bfa4cdce0b6feb0282175911cb378f5e184a6fff9f276fdd82f97a9c74cba519dcdf24086105a91c111d4ce1a6c4b618889e
7
- data.tar.gz: a68d08ac29df736191b86eb51dfaf383bdf29ce345b72e5465e3a4dab9e75bcda3715f02d95c351e9bf4a4a98f1474194b14b1aea808360f6a2f96f156338aff
6
+ metadata.gz: e30d29de112fcef550d19e4d3597719381b8dcb4c9213290ec87d15f01854c72454200598c5b0e1babb09bafb50a16521e2c56b4b5da5ceab627d1f092919983
7
+ data.tar.gz: 580dd518c0f95e2be4bc9e19517552f0e7cb2c8c7fa0af24d0db63530961679a154ef1f5794a0788d38d507d453b70777e2062ebbff5d17cee86a27c3ad00b48
@@ -11,10 +11,12 @@ module HNPosts
11
11
  def fetch_posts
12
12
  return @posts if @posts
13
13
 
14
- titles, points, comments = _titles, _points, _comments
15
- post_count = titles.size - 2
16
- @posts = (0..post_count).collect do | indx |
17
- Post.new title: titles[indx],
14
+ post_ids, titles, urls, points, comments = _post_ids, _titles, _urls, _points, _comments
15
+ post_count = post_ids.size
16
+ @posts = (0...post_count).collect do | indx |
17
+ Post.new post_id: post_ids[indx],
18
+ title: titles[indx],
19
+ url: urls[indx],
18
20
  points: points[indx],
19
21
  comments: comments[indx],
20
22
  position: (indx + 1)
@@ -25,10 +27,18 @@ module HNPosts
25
27
 
26
28
  attr_reader :hn_doc
27
29
 
30
+ def _post_ids
31
+ hn_doc.css('td > center > a').collect { |tag| /up_(\d+)/.match(tag.attributes['id'].value)[1] }
32
+ end
33
+
28
34
  def _titles
29
35
  hn_doc.css('td[class=title] a').collect { |tag| tag.text.strip }
30
36
  end
31
37
 
38
+ def _urls
39
+ hn_doc.css('td[class=title] a').collect { |tag| tag.attributes['href'].value }
40
+ end
41
+
32
42
  def _points
33
43
  hn_doc.css('td[class=subtext] span').collect { |tag| tag.text[/\d+/].to_i }
34
44
  end
data/lib/hnposts/post.rb CHANGED
@@ -2,17 +2,19 @@ module HNPosts
2
2
 
3
3
  class Post
4
4
 
5
- attr_accessor :title, :points, :comments, :position
5
+ attr_reader :post_id, :title, :url, :points, :comments, :position
6
6
 
7
7
  def initialize( options )
8
- @title = options[:title] || "No Title"
9
- @points = options[:points] || 0
10
- @comments = options[:comments] || 0
11
- @position = options[:position] || 0
8
+ @post_id = options[:post_id]
9
+ @title = options[:title]
10
+ @url = options[:url]
11
+ @points = options[:points]
12
+ @comments = options[:comments]
13
+ @position = options[:position]
12
14
  end
13
15
 
14
16
  def to_s
15
- "#{position}. #{title}, #{points} points #{comments} comments"
17
+ "#{post_id} - position #{position}, #{title}, #{points} points #{comments} comments, #{url}"
16
18
  end
17
19
 
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module HNPosts
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hnposts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sankaranarayanan Viswanathan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler