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 +4 -4
- data/lib/hnposts/fetcher.rb +14 -4
- data/lib/hnposts/post.rb +8 -6
- data/lib/hnposts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e82d7afe6c2a5c9fc820bb04b2b052a946f638b7
|
4
|
+
data.tar.gz: 298908d01dc037d5a236d310edb4ae60d34822ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e30d29de112fcef550d19e4d3597719381b8dcb4c9213290ec87d15f01854c72454200598c5b0e1babb09bafb50a16521e2c56b4b5da5ceab627d1f092919983
|
7
|
+
data.tar.gz: 580dd518c0f95e2be4bc9e19517552f0e7cb2c8c7fa0af24d0db63530961679a154ef1f5794a0788d38d507d453b70777e2062ebbff5d17cee86a27c3ad00b48
|
data/lib/hnposts/fetcher.rb
CHANGED
@@ -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 =
|
16
|
-
@posts = (0
|
17
|
-
Post.new
|
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
|
-
|
5
|
+
attr_reader :post_id, :title, :url, :points, :comments, :position
|
6
6
|
|
7
7
|
def initialize( options )
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
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}
|
17
|
+
"#{post_id} - position #{position}, #{title}, #{points} points #{comments} comments, #{url}"
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
data/lib/hnposts/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|