longforms 0.1.0 → 0.1.1
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/cli.rb +42 -18
- 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: 7b59d494d30a9d0843ebe558e3b7437c52a53264
|
4
|
+
data.tar.gz: 478accaee6f8ee3823962755a9406ee7390ceb30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa48bf2c38dc2e6385d56c37cd910b67b7a287ae8b486d0f0eb9b86f9940292a382b7596b4fee48ba7ad3a141ffab5a1ef04167b4ada1bfc8c3fe8018109ab0b
|
7
|
+
data.tar.gz: ae22a182f47b3a38fad487b9f5d31f53bdfd02e01e4c293b91e884ec3bebf67e64ea6887ca8f64530b0d9b8aa5cab5b7c0c472048f2a7f8de525b0d28de1421a
|
data/lib/cli.rb
CHANGED
@@ -10,21 +10,21 @@ class CLI
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def run
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
@page_num = 1
|
14
|
+
make_articles
|
15
|
+
display_articles
|
16
|
+
menu
|
17
17
|
end
|
18
18
|
|
19
19
|
def make_articles(page_url = "https://longreads.com/picks")
|
20
|
-
Article.all.clear
|
21
20
|
articles_array = Scraper.scrape_index_page(page_url)
|
22
21
|
Article.create_from_collection(articles_array)
|
22
|
+
articles_array.uniq!
|
23
23
|
end
|
24
24
|
|
25
|
-
def display_articles
|
26
|
-
Article.all.
|
27
|
-
puts "#{index
|
25
|
+
def display_articles(from_number = 1)
|
26
|
+
Article.all[from_number-1, 10].each.with_index(from_number) do |article, index|
|
27
|
+
puts "#{index}. #{article.title}\n".colorize(:blue)
|
28
28
|
puts "#{article.description}"
|
29
29
|
puts "----------------------".colorize(:green)
|
30
30
|
end
|
@@ -42,27 +42,51 @@ class CLI
|
|
42
42
|
puts ""
|
43
43
|
puts " Link:".colorize(:light_blue) + " #{Article.all[index].url}"
|
44
44
|
puts "----------------------".colorize(:green)
|
45
|
-
menu
|
46
45
|
end
|
47
46
|
|
48
47
|
def menu
|
49
|
-
|
48
|
+
display_instructions(@page_num)
|
50
49
|
input = gets.chomp
|
51
|
-
if input.downcase == "
|
52
|
-
|
53
|
-
page_num
|
54
|
-
|
55
|
-
|
56
|
-
elsif
|
50
|
+
if input.downcase == "next"
|
51
|
+
@page_num += 1
|
52
|
+
make_articles(page_url(@page_num))
|
53
|
+
display_articles((@page_num*10)-9)
|
54
|
+
display_instructions(@page_num)
|
55
|
+
elsif input.downcase == "back" && @page_num != 1
|
56
|
+
@page_num -= 1
|
57
|
+
display_articles((@page_num*10)-9)
|
58
|
+
display_instructions(@page_num)
|
59
|
+
elsif input.downcase == "back" && @page_num == 1
|
60
|
+
puts "Sorry! You're already on the first page of articles.".colorize(:red)
|
61
|
+
puts ""
|
62
|
+
display_instructions(@page_num)
|
63
|
+
elsif (1..1000).include?(input.to_i)
|
57
64
|
display_article_details(input.to_i - 1)
|
65
|
+
puts "Would you like to view another article? Enter Y or N."
|
66
|
+
input = gets.chomp.downcase
|
67
|
+
if input == "y"
|
68
|
+
run
|
69
|
+
else
|
70
|
+
quit
|
71
|
+
end
|
58
72
|
elsif input == "exit"
|
59
|
-
|
60
|
-
@active = false
|
73
|
+
quit
|
61
74
|
else
|
62
75
|
menu
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
79
|
+
def quit
|
80
|
+
puts ""
|
81
|
+
puts "Thank you for reading today!"
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
def display_instructions(page_num)
|
86
|
+
puts "You are on page #{page_num}. Type 'next' or 'back' to navigate between pages. Type the number of an article to view its details."
|
87
|
+
puts ""
|
88
|
+
end
|
89
|
+
|
66
90
|
def page_url(page_num)
|
67
91
|
"https://longreads.com/picks" + "/?page=#{page_num}"
|
68
92
|
end
|