hacker_term 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c47a1dd8c8aca3cccdae227fe501dbae9bf4d075
4
+ data.tar.gz: ab1f6f819c18b7e7053f43886262b35bd6fa24dc
5
+ SHA512:
6
+ metadata.gz: 42fd5b2cec0517e572e19a3fe4c2ec0049d23d6030c284ea1d310b1d217ad674577f288e29d6770b7428af1faf2dd7e81bb35af6ade50a4366a3f43eebcef38e
7
+ data.tar.gz: 7164dbac8303353e6c8a26323573dd297c4f7300db7cbe81f02ae75a46d2f38b0c3b003861c92eb8a44bdc3f1489b97e6e488654691241457b74dc27cc66d5ba
data/.gitignore CHANGED
File without changes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml CHANGED
@@ -1,8 +1,3 @@
1
1
  language: ruby
2
- rvm:
3
- - "1.9.2"
4
- - "1.9.3"
5
- - jruby-19mode # JRuby in 1.9 mode
6
- - rbx-19mode
7
2
  # uncomment this line if your project needs to run something other than `rake`:
8
3
  script: bundle exec rspec spec
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/data/comments.json CHANGED
File without changes
data/data/data.json CHANGED
File without changes
data/data/lorem.txt CHANGED
File without changes
data/hacker_term.gemspec CHANGED
@@ -11,11 +11,13 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Read Hacker News on the Terminal}
12
12
  gem.summary = %q{Allows the reading, sorting and opening of HN articles from the terminal.}
13
13
  gem.homepage = "https://github.com/ciaranarcher/hacker_term"
14
- gem.add_dependency('rest-client')
15
- gem.add_dependency('launchy')
16
- gem.add_dependency('clipboard')
17
- gem.add_development_dependency('rspec')
18
-
14
+ gem.add_dependency('curses', '~> 1.0')
15
+ gem.add_dependency('rest-client', '~> 1.7')
16
+ gem.add_dependency('launchy', '~> 2.4')
17
+ gem.add_dependency('clipboard', '~> 1.0')
18
+ gem.add_development_dependency('rspec', '~> 2.12')
19
+ gem.add_development_dependency('bump', '~> 0.1')
20
+
19
21
  gem.files = `git ls-files`.split($/)
20
22
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
23
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
data/lib/hacker_term.rb CHANGED
@@ -21,13 +21,13 @@ module HackerTerm
21
21
  when "Q"
22
22
  @ui.close
23
23
  exit
24
-
24
+
25
25
  when "UP"
26
26
  @page.change_line_pos :down
27
-
27
+
28
28
  when "DOWN"
29
29
  @page.change_line_pos :up
30
-
30
+
31
31
  when "K"
32
32
  @page.change_line_pos :down
33
33
 
@@ -36,23 +36,23 @@ module HackerTerm
36
36
 
37
37
  when "O"
38
38
  open_link(@page.selected_url)
39
-
39
+
40
40
  when "D"
41
41
  open_link(@page.selected_comments_url)
42
-
42
+
43
43
  when "A"
44
44
  load
45
45
  @page.change_line_pos :reset
46
-
46
+
47
47
  when "S"
48
48
  @page.sort_on!(:score)
49
-
49
+
50
50
  when "R"
51
51
  @page.sort_on!(:rank)
52
-
52
+
53
53
  when "T"
54
54
  @page.sort_on!(:title)
55
-
55
+
56
56
  when "C"
57
57
  @page.sort_on!(:comments)
58
58
  end
@@ -84,7 +84,15 @@ module HackerTerm
84
84
  def read_json
85
85
  local_proxy = get_local_proxy
86
86
  RestClient.proxy = local_proxy unless local_proxy.nil?
87
- RestClient.get 'http://hndroidapi.appspot.com/news/format/json/page/'
87
+ RestClient.get "http://hndroidapi.appspot.com/news/format/json/page/?appid=#{app_id}&guid=#{token}"
88
+ end
89
+
90
+ def app_id
91
+ "hacker_term"
92
+ end
93
+
94
+ def token
95
+ "98c64825ecc442a6b4d95a419f0f323b"
88
96
  end
89
97
 
90
98
  def get_local_proxy
File without changes
@@ -13,17 +13,17 @@ module HackerTerm
13
13
  attr_reader :data, :mean_score, :median_score, :mode_score, :sorted_by, :line_pos
14
14
 
15
15
  def initialize(data)
16
- begin
16
+ begin
17
17
  @data = JSON.parse(data)['items']
18
18
  rescue JSON::ParserError
19
19
  raise "JSON appears to be malformed: #{unescaped}" # Bomb out for now...
20
20
  end
21
-
21
+
22
22
  add_missing_keys!
23
23
  format_numbers!
24
24
  format_urls!
25
25
  unescape_titles!
26
-
26
+
27
27
  calculate_mean_score
28
28
  calculate_median_score
29
29
  calculate_mode_score
@@ -66,7 +66,7 @@ module HackerTerm
66
66
  def selected_url
67
67
  @data[@line_pos - 1]['url']
68
68
  end
69
-
69
+
70
70
  def selected_comments_url
71
71
  "http://news.ycombinator.com/item?id=" + @data[@line_pos - 1]['item_id']
72
72
  end
@@ -38,7 +38,7 @@ module HackerTerm
38
38
  def output_line(line_num, data)
39
39
  setpos(line_num, 0)
40
40
  padding_right = @total_width - data.length - @padding_left
41
- padding_right = 0 if padding_right < 0
41
+ padding_right = 0 if padding_right < 0
42
42
  addstr((" " * @padding_left) + data + (" " * padding_right))
43
43
  end
44
44
 
@@ -50,11 +50,11 @@ module HackerTerm
50
50
 
51
51
  def <<(str)
52
52
  throw 'invalid type' unless str.is_a? String
53
- output_line(next_line_num, str)
53
+ output_line(next_line_num, str)
54
54
  end
55
55
 
56
56
  def divider
57
- output_divider(next_line_num)
57
+ output_divider(next_line_num)
58
58
  end
59
59
 
60
60
  def output(&blk)
@@ -75,7 +75,7 @@ module HackerTerm
75
75
  # A nicer way to do this is always put the title last, and assume last column gets
76
76
  # remaining width. That way we can just loop through our cols, rather than hardcoding
77
77
  # them as per example below. I'm sticking to this because I want the title listed second.
78
- width_excl_title = @cols.inject(0) do |width, col|
78
+ width_excl_title = @cols.inject(0) do |width, col|
79
79
  width += (3 + col.length)
80
80
  end
81
81
  attrset color_pair(2)
@@ -89,7 +89,7 @@ module HackerTerm
89
89
  output do |buff|
90
90
  buff.divider
91
91
  attrset color_pair(1)
92
- buff << sprintf("Sorted by: %7s | Scores: Mean: %4.2f | Median: %4.2f | Mode: %4.2f",
92
+ buff << sprintf("Sorted by: %7s | Scores: Mean: %4.2f | Median: %4.2f | Mode: %4.2f",
93
93
  sorted_by, mean, median, mode)
94
94
  buff.divider
95
95
  end
@@ -107,7 +107,7 @@ module HackerTerm
107
107
  attrset color_pair(0)
108
108
  end
109
109
 
110
- self << sprintf("%4s | %-#{@title_width}s | %5s | %8s",
110
+ self << sprintf("%4s | %-#{@title_width}s | %5s | %8s",
111
111
  rank, title, data['score'], data['comments'])
112
112
  end
113
113
 
@@ -119,14 +119,14 @@ module HackerTerm
119
119
  def show(page_data)
120
120
  draw_header
121
121
 
122
- page_data.data.each_index do |i|
122
+ page_data.data.each_index do |i|
123
123
  line_data = page_data.data.fetch(i)
124
- draw_item_line(line_data['rank'], line_data, page_data.line_pos == i + 1)
124
+ draw_item_line(line_data['rank'], line_data, page_data.line_pos == i + 1)
125
125
  end
126
126
 
127
- draw_footer(page_data.sorted_by,
128
- page_data.mean_score,
129
- page_data.median_score,
127
+ draw_footer(page_data.sorted_by,
128
+ page_data.mean_score,
129
+ page_data.median_score,
130
130
  page_data.mode_score
131
131
  )
132
132
  end
@@ -161,4 +161,4 @@ module HackerTerm
161
161
  @options ||= {}
162
162
  end
163
163
  end
164
- end
164
+ end
@@ -1,3 +1,3 @@
1
1
  module HackerTerm
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,7 +8,7 @@ module HackerTerm
8
8
 
9
9
  it 'creates an array of comments' do
10
10
  comments = CommentsData.new many_comments
11
- comments.data.should be_instance_of Array
11
+ expect(comments.data).to be_instance_of Array
12
12
  end
13
13
 
14
14
  it 'removes HTML entities' do
@@ -29,7 +29,7 @@ module HackerTerm
29
29
  }'
30
30
 
31
31
  comments = CommentsData.new data
32
- comments.data.first['comment'].should_not match /&amp;/
32
+ expect(comments.data.first['comment']).to_not match /&amp;/
33
33
  end
34
34
 
35
35
  it 'splits a long line into fixed width lines preserving words' do
@@ -51,8 +51,7 @@ module HackerTerm
51
51
  }
52
52
  }
53
53
  comments = CommentsData.new data
54
- p comments.data
55
54
  end
56
55
  end
57
56
  end
58
- end
57
+ end
@@ -4,7 +4,7 @@ module HackerTerm
4
4
  describe PageData do
5
5
  describe 'formatting JSON' do
6
6
  before(:each) do
7
- @data =
7
+ @data =
8
8
  '{"items":[
9
9
  {
10
10
  "title":"NextId",
@@ -26,74 +26,73 @@ module HackerTerm
26
26
  end
27
27
 
28
28
  it 'adds score node' do
29
- @pd.data.first.should have_key 'score'
29
+ expect(@pd.data.first).to have_key 'score'
30
30
  end
31
31
 
32
32
  it 'adds comments node' do
33
- @pd.data.first.should have_key 'comments'
33
+ expect(@pd.data.first).to have_key 'comments'
34
34
  end
35
35
 
36
36
  it 'formats score node as a number when the node didn\'t exist' do
37
- @pd.data.first['score'].should == '0'
37
+ expect(@pd.data.first['score']).to be == '0'
38
38
  end
39
39
 
40
40
  it 'formats score node as a number when text is present' do
41
- @pd.data.last['score'].should == '260'
41
+ expect(@pd.data.last['score']).to be == '260'
42
42
  end
43
43
 
44
44
  it 'formats comments node as a number when the node didn\'t exist' do
45
- @pd.data.first['comments'].should == '0'
45
+ expect(@pd.data.first['comments']).to be == '0'
46
46
  end
47
47
 
48
48
  it 'formats comments node as a number when text is present' do
49
- @pd.data.last['comments'].should == '122'
49
+ expect(@pd.data.last['comments']).to be == '122'
50
50
  end
51
51
 
52
52
  it 'unescapes HTML entities in title where present' do
53
- @pd.data.last['title'].should_not match /&amp;/
53
+ expect(@pd.data.last['title']).to_not match /&amp;/
54
54
  end
55
-
56
55
  end
57
56
 
58
57
  describe 'calculating stats' do
59
58
  before(:each) do
60
- @page_data = PageData.new File.read './data/data.json'
59
+ @page_data = PageData.new File.read './data/data.json'
61
60
  end
62
61
 
63
62
  it 'provides a mean' do
64
- @page_data.mean_score.should == 193.59375
63
+ expect(@page_data.mean_score).to be == 193.59375
65
64
  end
66
65
 
67
66
  it 'provides a median' do
68
- @page_data.median_score.should == 135.0
67
+ expect(@page_data.median_score).to be == 135.0
69
68
  end
70
69
 
71
70
  it 'provides a mode' do
72
- @page_data.mode_score.should == 0
71
+ expect(@page_data.mode_score).to be == 0
73
72
  end
74
73
  end
75
-
74
+
76
75
  describe 'formatting URLs' do
77
76
  before(:each) do
78
77
  @pg = PageData.new File.read './data/data.json'
79
78
  end
80
-
79
+
81
80
  it 'provides a URL for actual article' do
82
- @pg.selected_url.should == "http://powwow.cc/"
81
+ expect(@pg.selected_url).to be == "http://powwow.cc/"
83
82
  end
84
-
83
+
85
84
  it 'provides a URL for article comments' do
86
- @pg.selected_comments_url.should == "http://news.ycombinator.com/item?id=4924763"
85
+ expect(@pg.selected_comments_url).to be == "http://news.ycombinator.com/item?id=4924763"
87
86
  end
88
87
 
89
88
  it 'links to HN directly if URL is not absolute' do
90
- @pg.data.last['url'].should == 'http://news.ycombinator.com/item?id=4992617'
89
+ expect(@pg.data.last['url']).to be == 'http://news.ycombinator.com/item?id=4992617'
91
90
  end
92
91
  end
93
92
 
94
93
  describe 'sorting' do
95
94
  before(:each) do
96
- @data =
95
+ @data =
97
96
  '{"items":[
98
97
  {
99
98
  "title":"First Article",
@@ -130,39 +129,39 @@ module HackerTerm
130
129
  end
131
130
 
132
131
  it 'preserves natural ordering as default' do
133
- @pd.data.first['title'].should == 'First Article'
134
- @pd.data.last['title'].should == 'Third Article'
132
+ expect(@pd.data.first['title']).to be == 'First Article'
133
+ expect(@pd.data.last['title']).to be == 'Third Article'
135
134
  end
136
135
 
137
136
  it 'sorts by score when requested' do
138
137
  @pd.sort_on!(:score)
139
- @pd.data.first['title'].should == 'Second Article'
140
- @pd.data.last['title'].should == 'First Article'
138
+ expect(@pd.data.first['title']).to be == 'Second Article'
139
+ expect(@pd.data.last['title']).to be == 'First Article'
141
140
  end
142
141
 
143
142
  it 'sorts by number of comments when requested' do
144
143
  @pd.sort_on!(:comments)
145
- @pd.data.first['title'].should == 'First Article'
146
- @pd.data.last['title'].should == 'Third Article'
144
+ expect(@pd.data.first['title']).to be == 'First Article'
145
+ expect(@pd.data.last['title']).to be == 'Third Article'
147
146
  end
148
147
 
149
148
  it 'sorts by rank when requested' do
150
149
  @pd.sort_on!(:rank)
151
- @pd.data.first['title'].should == 'First Article'
152
- @pd.data.last['title'].should == 'Third Article'
150
+ expect(@pd.data.first['title']).to be == 'First Article'
151
+ expect(@pd.data.last['title']).to be == 'Third Article'
153
152
  end
154
153
 
155
154
  it 'sorts by title when requested' do
156
155
  @pd.sort_on!(:title)
157
- @pd.data.first['title'].should == 'First Article'
158
- @pd.data.last['title'].should == 'Third Article'
156
+ expect(@pd.data.first['title']).to be == 'First Article'
157
+ expect(@pd.data.last['title']).to be == 'Third Article'
159
158
  end
160
159
 
161
160
  it 're-sorts by rank when requested' do
162
161
  @pd.sort_on!(:comments)
163
162
  @pd.sort_on!(:rank)
164
- @pd.data.first['title'].should == 'First Article'
165
- @pd.data.last['title'].should == 'Third Article'
163
+ expect(@pd.data.first['title']).to be == 'First Article'
164
+ expect(@pd.data.last['title']).to be == 'Third Article'
166
165
  end
167
166
  end
168
167
  end
metadata CHANGED
@@ -1,73 +1,110 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hacker_term
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Ciaran Archer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2013-01-09 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rest-client
11
+ date: 2016-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curses
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
17
21
  prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
24
34
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: launchy
28
35
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: launchy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
35
48
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: clipboard
39
49
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: clipboard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
46
62
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
49
70
  name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.12'
76
+ type: :development
50
77
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bump
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
57
90
  type: :development
58
- version_requirements: *id004
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
59
97
  description: Read Hacker News on the Terminal
60
- email:
98
+ email:
61
99
  - ciaran.archer@gmail.com
62
- executables:
100
+ executables:
63
101
  - hacker_term
64
102
  extensions: []
65
-
66
103
  extra_rdoc_files: []
67
-
68
- files:
69
- - .gitignore
70
- - .travis.yml
104
+ files:
105
+ - ".gitignore"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
71
108
  - Gemfile
72
109
  - Gemfile.lock
73
110
  - LICENSE.txt
@@ -87,31 +124,27 @@ files:
87
124
  - spec/page_data_spec.rb
88
125
  homepage: https://github.com/ciaranarcher/hacker_term
89
126
  licenses: []
90
-
127
+ metadata: {}
91
128
  post_install_message:
92
129
  rdoc_options: []
93
-
94
- require_paths:
130
+ require_paths:
95
131
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
99
134
  - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
105
139
  - - ">="
106
- - !ruby/object:Gem::Version
107
- version: "0"
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
108
142
  requirements: []
109
-
110
143
  rubyforge_project:
111
- rubygems_version: 1.8.24
144
+ rubygems_version: 2.5.1
112
145
  signing_key:
113
- specification_version: 3
146
+ specification_version: 4
114
147
  summary: Allows the reading, sorting and opening of HN articles from the terminal.
115
- test_files:
148
+ test_files:
116
149
  - spec/comments_data_spec.rb
117
150
  - spec/page_data_spec.rb