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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19cfb1ab3fbb5072c0a8cf152e586320e54503f2
4
- data.tar.gz: ae26dc172f3c7f1be00eac01fa8f3655fe8a3246
3
+ metadata.gz: 69a64c2e0e854732484489a18aa7216dc5624a38
4
+ data.tar.gz: d45aef0a56a7ca1419d04419bf3951268e2305f1
5
5
  SHA512:
6
- metadata.gz: 9ebad380cbe2c270e1ab0deecd65b2acaa3981b97bde7df59f52bc4c17c6c252b267356d57f7ad2c34bf1cc1e9db88f108dedd5c29e1fcfe4975ac48a349f779
7
- data.tar.gz: 66ddef15c291fa00fd5b1a5c59f1c59c9769bffd3a2873c90e481b2d6de392284baa2804b7ec3b9971ecd03b742d99073b198f75a2f4444b8f91254f547f3a74
6
+ metadata.gz: 65307c1c2b1f22140ee7fb7736a6b5fcdde3025749198f351d83f1433d8fbe8ddf33123eb9fc0827b3825a76e07526db7d0a04dd3edd665929097018a7d5296c
7
+ data.tar.gz: 854da69febe17708f6bde650e4e3f5e6bbf0d18db8bb4c48e8f7b0f56623d2e663120f68b9030fe14bfc3129ae78a81dcd930901684c3334d779a778a3a1213c
@@ -21,9 +21,7 @@ class TopHeadlines::CLI
21
21
  if @input == "ALL"
22
22
  list_all_headlines_banner
23
23
  list_all_headlines
24
- # open_headline_in_browser
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
- open_headline_in_browser
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 open_headline_in_browser
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
- while @num.to_i.between?(1,5) && !num_included_in_menu_if_statements
99
- # if @input == "ALL"
100
- # @input == TopHeadlines::Source.all.keys[@num/3]
101
- # headline = TopHeadlines::Source.scrape_headlines(@input)[@num.to_i-1]
102
- # puts "=> Opening..."
103
-
104
- # sleep(2)
105
- # url = TopHeadlines::Source.scrape_urls(@input)[@num.to_i-1]
106
- # system("open", url)
107
-
108
- # sleep(1)
109
- # puts "\nSelect another headline number to open full article in the browser."
110
- # print "YOUR SELECTION: "
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
@@ -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].each {|headline| puts "#{article_sum+1}. #{headline}"; article_sum += 1}
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
@@ -1,3 +1,3 @@
1
1
  module TopHeadlines
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top-headlines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zachnewburgh