hacker_term 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.
data/data/data.json CHANGED
@@ -299,6 +299,16 @@
299
299
  "title":"NextId",
300
300
  "url":"/news2",
301
301
  "description":"hn next id news2 "
302
- }
302
+ },
303
+ {
304
+ "title": "Ask HN: Who is hiring? (January 2013)",
305
+ "url": "item?id=4992617",
306
+ "score": "175 points",
307
+ "user": "whoishiring",
308
+ "comments": "140 comments",
309
+ "time": "11 hours ago",
310
+ "item_id": "4992617",
311
+ "description": "175 points points by whoishiring 11 hours ago | 140 comments"
312
+ }
303
313
  ]
304
314
  }
@@ -16,6 +16,7 @@ module HackerTerm
16
16
 
17
17
  add_missing_keys!
18
18
  format_numbers!
19
+ format_urls!
19
20
 
20
21
  calculate_mean_score
21
22
  calculate_median_score
@@ -55,6 +56,10 @@ module HackerTerm
55
56
  def selected_url
56
57
  @data[@line_pos - 1]['url']
57
58
  end
59
+
60
+ def selected_comments_url
61
+ "http://news.ycombinator.com/item?id=" + @data[@line_pos - 1]['item_id']
62
+ end
58
63
 
59
64
  private
60
65
 
@@ -108,5 +113,13 @@ module HackerTerm
108
113
  item['score'] = '0' unless item['score'].is_num?
109
114
  end
110
115
  end
116
+
117
+ def format_urls!
118
+ # Add HN domain for posts without an external link
119
+ @data.each do |item|
120
+ item['url'] = "http://news.ycombinator.com/#{item['url']}" if item['url'] =~ /^item\?id=[0-9]+/
121
+ end
122
+ end
123
+
111
124
  end
112
125
  end
@@ -52,7 +52,8 @@ module HackerTerm
52
52
  output_divider(next_line_num)
53
53
  attrset color_pair(1)
54
54
  output_line(next_line_num, "HACKER NEWS TERMINAL - thanks to http://hndroidapi.appspot.com")
55
- output_line(next_line_num, "COMMANDS: Select (Arrows), Open (O), Refresh (A) | Sort by Rank (R), Score (S), Comments (C), Title (T) | Quit (Q)")
55
+ output_line(next_line_num, "CMDS: Select (Arrows), Open Item (O), Open Item Discussion (D), Refresh (A)")
56
+ output_line(next_line_num, "CMDS CONT: Sort by Rank (R), Score (S), Comments (C), Title (T) | Quit (Q)")
56
57
  output_divider(next_line_num)
57
58
 
58
59
  # Get width_excl_title, i.e. width of all columns + some extra for |'s and spacing.
@@ -1,3 +1,3 @@
1
1
  module HackerTerm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/hacker_term.rb CHANGED
@@ -35,7 +35,10 @@ module HackerTerm
35
35
  @page.change_line_pos :up
36
36
 
37
37
  when "O"
38
- launch
38
+ open_link(@page.selected_url)
39
+
40
+ when "D"
41
+ open_link(@page.selected_comments_url)
39
42
 
40
43
  when "A"
41
44
  load
@@ -63,13 +66,13 @@ module HackerTerm
63
66
 
64
67
  private
65
68
 
66
- def launch
69
+ def open_link(url)
67
70
  # Attempts to launch a browser; writes URL to clipboard in any case
68
71
  begin
69
- Launchy.open @page.selected_url # May not work in some Linux flavors
72
+ Launchy.open url # May not work in some Linux flavors
70
73
  rescue
71
74
  ensure
72
- Clipboard.copy @page.selected_url
75
+ Clipboard.copy url
73
76
  end
74
77
  end
75
78
 
@@ -57,17 +57,35 @@ module HackerTerm
57
57
  end
58
58
 
59
59
  it 'provides a mean' do
60
- @page_data.mean_score.should == 194.19354838709677
60
+ @page_data.mean_score.should == 193.59375
61
61
  end
62
62
 
63
63
  it 'provides a median' do
64
- @page_data.median_score.should == 131
64
+ @page_data.median_score.should == 135.0
65
65
  end
66
66
 
67
67
  it 'provides a mode' do
68
68
  @page_data.mode_score.should == 0
69
69
  end
70
70
  end
71
+
72
+ describe 'formatting URLs' do
73
+ before(:each) do
74
+ @pg = HackerTerm::PageData.new File.read './data/data.json'
75
+ end
76
+
77
+ it 'provides a URL for actual article' do
78
+ @pg.selected_url.should == "http://powwow.cc/"
79
+ end
80
+
81
+ it 'provides a URL for article comments' do
82
+ @pg.selected_comments_url.should == "http://news.ycombinator.com/item?id=4924763"
83
+ end
84
+
85
+ it 'links to HN directly if URL is not absolute' do
86
+ @pg.data.last['url'].should == 'http://news.ycombinator.com/item?id=4992617'
87
+ end
88
+ end
71
89
 
72
90
  describe 'sorting' do
73
91
  before(:each) do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hacker_term
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ciaran Archer
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-01-01 00:00:00 Z
13
+ date: 2013-01-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client