top-headlines 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/top-headlines/cli.rb +47 -38
- data/lib/top-headlines/source.rb +1 -2
- data/lib/top-headlines/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69a64c2e0e854732484489a18aa7216dc5624a38
|
4
|
+
data.tar.gz: d45aef0a56a7ca1419d04419bf3951268e2305f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65307c1c2b1f22140ee7fb7736a6b5fcdde3025749198f351d83f1433d8fbe8ddf33123eb9fc0827b3825a76e07526db7d0a04dd3edd665929097018a7d5296c
|
7
|
+
data.tar.gz: 854da69febe17708f6bde650e4e3f5e6bbf0d18db8bb4c48e8f7b0f56623d2e663120f68b9030fe14bfc3129ae78a81dcd930901684c3334d779a778a3a1213c
|
data/lib/top-headlines/cli.rb
CHANGED
@@ -21,9 +21,7 @@ class TopHeadlines::CLI
|
|
21
21
|
if @input == "ALL"
|
22
22
|
list_all_headlines_banner
|
23
23
|
list_all_headlines
|
24
|
-
|
25
|
-
puts request_input_full_menu
|
26
|
-
print "YOUR SELECTION: "
|
24
|
+
all_headlines_open_in_browser
|
27
25
|
elsif @input == "SOURCES"
|
28
26
|
news_sources_banner
|
29
27
|
news_sources
|
@@ -31,7 +29,7 @@ class TopHeadlines::CLI
|
|
31
29
|
print "YOUR SELECTION: "
|
32
30
|
elsif source_includes?(@input)
|
33
31
|
list_headlines_from_source
|
34
|
-
|
32
|
+
headlines_from_source_open_in_browser
|
35
33
|
elsif @input != "EXIT"
|
36
34
|
invalid_entry
|
37
35
|
else
|
@@ -91,46 +89,57 @@ class TopHeadlines::CLI
|
|
91
89
|
puts "\n"
|
92
90
|
end
|
93
91
|
|
94
|
-
def
|
92
|
+
def all_headlines_open_in_browser
|
93
|
+
puts "Select source and headline number to open the full article in the browser. \n(e.g. 'cnn 3') \n\nAlternatively, #{request_input_full_menu.downcase}"
|
94
|
+
print "\nYOUR SELECTION: "
|
95
|
+
@num = gets.strip.upcase
|
96
|
+
|
97
|
+
while @num[-1].to_i.between?(1,5) && !num_included_in_menu_if_statements
|
98
|
+
source = @num[0...-1].strip.upcase
|
99
|
+
headline = @num.strip[-1].to_i
|
100
|
+
|
101
|
+
open_url(source, headline)
|
102
|
+
|
103
|
+
sleep(1)
|
104
|
+
puts "\nSelect another source and headline number to open full article in the browser. \n\nAlternatively, #{request_input_full_menu.downcase}"
|
105
|
+
print "\nYOUR SELECTION: "
|
106
|
+
@num = gets.strip.upcase
|
107
|
+
end
|
108
|
+
|
109
|
+
num_included_in_menu_if_statements ? @input = @num : invalid_entry
|
110
|
+
menu_if_statement
|
111
|
+
end
|
112
|
+
|
113
|
+
def headlines_from_source_open_in_browser
|
95
114
|
puts "Select headline number to open the full article in the browser. \n\nAlternatively, #{request_input_full_menu.downcase}"
|
96
115
|
print "\nYOUR SELECTION: "
|
97
116
|
@num = gets.strip.upcase
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# @num = gets.strip.upcase
|
112
|
-
# @input = @num if @num == "EXIT"
|
113
|
-
# else
|
114
|
-
headline = TopHeadlines::Source.scrape_headlines(@input)[@num.to_i-1]
|
115
|
-
puts "\n=> You selected the #{@num.to_i.ordinalize} headline: '#{headline}'."
|
116
|
-
puts "=> Opening..."
|
117
|
-
|
118
|
-
sleep(2)
|
119
|
-
url = TopHeadlines::Source.scrape_urls(@input)[@num.to_i-1]
|
120
|
-
system("open", url)
|
121
|
-
|
122
|
-
sleep(1)
|
123
|
-
puts "\nSelect another headline number to open full article in the browser. \n\nAlternatively, #{request_input_full_menu.downcase}"
|
124
|
-
print "\nYOUR SELECTION: "
|
125
|
-
@num = gets.strip.upcase
|
126
|
-
@input = @num if num_included_in_menu_if_statements
|
127
|
-
# end
|
128
|
-
end
|
129
|
-
invalid_entry unless num_included_in_menu_if_statements
|
130
|
-
@input = @num if num_included_in_menu_if_statements
|
117
|
+
|
118
|
+
while @num.to_i.between?(1,5) && !num_included_in_menu_if_statements
|
119
|
+
open_url(@input, @num)
|
120
|
+
|
121
|
+
sleep(1)
|
122
|
+
puts "\nSelect another headline number to open full article in the browser. \n\nAlternatively, #{request_input_full_menu.downcase}"
|
123
|
+
print "\nYOUR SELECTION: "
|
124
|
+
@num = gets.strip.upcase
|
125
|
+
|
126
|
+
@input = @num if num_included_in_menu_if_statements
|
127
|
+
end
|
128
|
+
|
129
|
+
num_included_in_menu_if_statements ? @input = @num : invalid_entry
|
131
130
|
menu_if_statement
|
132
131
|
end
|
133
132
|
|
133
|
+
def open_url(source, number)
|
134
|
+
headline = TopHeadlines::Source.scrape_headlines(source)[number.to_i-1]
|
135
|
+
puts "\n=> You selected the #{number.to_i.ordinalize} headline: '#{headline}'."
|
136
|
+
puts "=> Opening..."
|
137
|
+
|
138
|
+
sleep(2)
|
139
|
+
url = TopHeadlines::Source.scrape_urls(source)[number.to_i-1]
|
140
|
+
url != nil ? system("open", url) : invalid_entry
|
141
|
+
end
|
142
|
+
|
134
143
|
def num_included_in_menu_if_statements
|
135
144
|
@num == "EXIT" || @num == "ALL" || @num == "SOURCES" || source_includes?(@num)
|
136
145
|
end
|
data/lib/top-headlines/source.rb
CHANGED
@@ -122,10 +122,9 @@ class TopHeadlines::Source
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def self.list_all_headlines
|
125
|
-
article_sum = 0
|
126
125
|
SOURCES.keys.sort.each do |source|
|
127
126
|
puts "*** #{source} ***"
|
128
|
-
scrape_headlines(source)[0,5].
|
127
|
+
scrape_headlines(source)[0,5].each_with_index {|headline, index| puts "#{index+1}. #{headline}"}
|
129
128
|
puts "\n"
|
130
129
|
end
|
131
130
|
end
|