whatsa 0.1.5 → 0.2.0
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/whatsa/cli.rb +50 -32
- data/lib/whatsa/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: 8113d3fcfece3bbf0348d753aa9c374fb4cceb5c
|
4
|
+
data.tar.gz: 268e16d05650463eb399a6d94a49c73ea03a841f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0b3b4ee5c3a1e72b2126d62256b94e1b599dca3c7113f73939ff3aaa07fcb49a91a9e610977ae4355b4b7503aa4a44d397dccf2f1eecfb910b10eac9a5a833
|
7
|
+
data.tar.gz: 982fc16934278e8f2eacb70943e1f1b2f226c3e1c2fed6cbc2f0946784e31618cce7d6c1c7bb2f233dec5bfc645ec12cfbc0012009e2c5e772ff4b460f18834e
|
data/lib/whatsa/cli.rb
CHANGED
@@ -24,10 +24,8 @@ class Whatsa::CLI
|
|
24
24
|
input = nil
|
25
25
|
loop do
|
26
26
|
print "> "
|
27
|
-
input = gets.strip
|
27
|
+
input = gets.strip.downcase
|
28
28
|
case input
|
29
|
-
when ""
|
30
|
-
puts "Please enter a valid input."
|
31
29
|
when "exit"
|
32
30
|
exit
|
33
31
|
when "help"
|
@@ -94,19 +92,25 @@ class Whatsa::CLI
|
|
94
92
|
choice = nil
|
95
93
|
loop do
|
96
94
|
choice = gets_command
|
97
|
-
in_choices = disambig.choices.detect { |c| c.downcase == choice
|
95
|
+
in_choices = disambig.choices.detect { |c| c.downcase == choice }
|
98
96
|
break if in_choices || choice.to_i > 0
|
99
97
|
end
|
100
98
|
disambig.choose_article(choice)
|
101
99
|
end
|
102
100
|
|
101
|
+
def get_sec_choice(article)
|
102
|
+
display_sections(article)
|
103
|
+
choice = gets_command
|
104
|
+
article.choose_section(choice)
|
105
|
+
end
|
106
|
+
|
103
107
|
def summarize(text)
|
104
108
|
system("clear")
|
105
109
|
return full(text) if text.summary == text.full_text
|
106
110
|
puts word_wrap(text.summary)
|
107
111
|
summary_helpline
|
108
112
|
input = gets_command
|
109
|
-
input
|
113
|
+
input == "more" ? full(text) : input
|
110
114
|
end
|
111
115
|
|
112
116
|
def full(text)
|
@@ -116,39 +120,53 @@ class Whatsa::CLI
|
|
116
120
|
gets_command
|
117
121
|
end
|
118
122
|
|
119
|
-
def categories(article)
|
120
|
-
display_sections(article)
|
121
|
-
choice = gets_command
|
122
|
-
section = article.choose_section(choice)
|
123
|
-
summarize(section)
|
124
|
-
end
|
125
|
-
|
126
123
|
def run
|
124
|
+
# This is the main method for running the CLI.
|
125
|
+
# It consists of three main parts:
|
126
|
+
# Part one - decorative - Welcome the user, give instructions for use
|
127
|
+
# Part two - initialize - Get a query from the user and try to make an
|
128
|
+
# article out of whatever comes back (results page,
|
129
|
+
# disambiguation page, or article)
|
130
|
+
# Part three - article - We've gotten to an article, display it to the user
|
131
|
+
# and loop as long as they wish to select different
|
132
|
+
# sections
|
133
|
+
|
134
|
+
|
135
|
+
##########
|
136
|
+
# PART ONE
|
137
|
+
|
127
138
|
welcome
|
128
139
|
instructions
|
129
140
|
|
130
|
-
loop do
|
131
|
-
# get a search term
|
132
|
-
input = ask
|
133
|
-
scraper = Whatsa::Scraper.new(input)
|
134
|
-
|
135
|
-
# get an article from the search, or restart the loop if it can't be found
|
136
|
-
if scraper.not_found?
|
137
|
-
puts "Hmmm... I don't know what '#{input}' means! Try something else."
|
138
|
-
next
|
139
|
-
elsif scraper.disambig?
|
140
|
-
article = get_dmb_choice(scraper.make_disambig)
|
141
|
-
else
|
142
|
-
article = scraper.make_article
|
143
|
-
end
|
144
141
|
|
145
|
-
|
146
|
-
|
142
|
+
##########
|
143
|
+
# PART TWO
|
144
|
+
|
145
|
+
# get a search term
|
146
|
+
input = ask
|
147
|
+
scraper = Whatsa::Scraper.new(input)
|
147
148
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
149
|
+
# get an article from the search, or restart the loop if it can't be found
|
150
|
+
if scraper.not_found?
|
151
|
+
print "Hmmm... I don't know what '#{input}' means!\nPress 'enter' to try something else."
|
152
|
+
gets
|
153
|
+
run
|
154
|
+
elsif scraper.disambig?
|
155
|
+
article = get_dmb_choice(scraper.make_disambig)
|
156
|
+
else
|
157
|
+
article = scraper.make_article
|
152
158
|
end
|
159
|
+
|
160
|
+
|
161
|
+
############
|
162
|
+
# PART THREE
|
163
|
+
|
164
|
+
# summarize that article
|
165
|
+
input = summarize(article)
|
166
|
+
|
167
|
+
# the only valid input here that would go uncaught is "other", so
|
168
|
+
# keep asking until you get a caught input (logic determined by
|
169
|
+
# #gets_command, e.g. "help", "exit", "new") or "other"
|
170
|
+
loop { input = input == "other" ? summarize(get_sec_choice(article)) : gets_command }
|
153
171
|
end
|
154
172
|
end
|
data/lib/whatsa/version.rb
CHANGED