project_euler_cli 1.1.1 → 1.1.2
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/Gemfile.lock +1 -1
- data/lib/project_euler_cli/archive_controller.rb +4 -10
- data/lib/project_euler_cli/archive_viewer.rb +8 -5
- data/lib/project_euler_cli/cli.rb +14 -11
- data/lib/project_euler_cli/concerns/scraper.rb +24 -16
- data/lib/project_euler_cli/page.rb +1 -1
- data/lib/project_euler_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6779626e07ad722584aa34beb3a2f3f2d0db6be50e19c77d8d1cbad050befb23
|
4
|
+
data.tar.gz: 5247763643de597db2903e2973332e921d5dcb954d0af74d0f9fe104934439eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d3dffe05c81249a33cf6a1eda98cd1df94d35da6280ae46e25068bcd22b0750705d4461486c0cc3df4b7fd37b405ef57185d902c72a3c0c1c6223d4b4e02e40
|
7
|
+
data.tar.gz: e70681145d9f1dfefa4528404b3e8ddedbd66332963f13a5c2f81818af94651da308311b170504815fdca67aac88199781e9b13ee6aa8c652827caa33f4d1abd
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ProjectEulerCli
|
2
2
|
|
3
|
-
# Controller class that manages the archive system. It holds the archive data
|
4
|
-
# by ArchiveViewer and ArchiveSearcher.
|
3
|
+
# Controller class that manages the archive system. It holds the archive data
|
4
|
+
# used by ArchiveViewer and ArchiveSearcher.
|
5
5
|
class ArchiveController
|
6
6
|
include Scraper
|
7
7
|
|
@@ -50,15 +50,9 @@ class ArchiveController
|
|
50
50
|
# get_page(id) => page
|
51
51
|
#
|
52
52
|
# Returns page number based on the ID of the problem. The recent page is
|
53
|
-
# considered page 0
|
53
|
+
# considered page 0.
|
54
54
|
def get_page(id)
|
55
|
-
|
56
|
-
0
|
57
|
-
elsif id.between?(1, Problem.total - 10)
|
58
|
-
(id - 1) / Page::PROBLEMS_PER_PAGE + 1
|
59
|
-
else
|
60
|
-
-1
|
61
|
-
end
|
55
|
+
id.between?(1, Problem.total - 10) ? (id - 1) / Page::LENGTH + 1 : 0
|
62
56
|
end
|
63
57
|
|
64
58
|
end
|
@@ -14,18 +14,21 @@ class ArchiveViewer
|
|
14
14
|
|
15
15
|
puts
|
16
16
|
|
17
|
-
(Problem.total).downto(Problem.total - 9)
|
17
|
+
(Problem.total).downto(Problem.total - 9) do |i|
|
18
|
+
puts "#{i} - #{@problems[i].title}"
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
|
-
# Displays the problem numbers and titles for an individual page of the
|
22
|
+
# Displays the problem numbers and titles for an individual page of the
|
23
|
+
# archive.
|
21
24
|
def display_page(page)
|
22
25
|
load_page(page, @problems)
|
23
26
|
|
24
27
|
puts
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
puts "#{i} - #{@problems[i].title}" unless i >= Problem.total - 9
|
29
|
+
i = (page - 1) * Page::LENGTH
|
30
|
+
Page::LENGTH.times do
|
31
|
+
puts "#{i += 1} - #{@problems[i].title}" unless i >= Problem.total - 9
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ProjectEulerCli #:nodoc:
|
2
2
|
|
3
|
-
# Manages the command line interface for the program. It uses the
|
4
|
-
# to access the site data.
|
3
|
+
# Manages the command line interface for the program. It uses the
|
4
|
+
# ArchiveController to access the site data.
|
5
5
|
class CLI
|
6
6
|
|
7
7
|
def initialize
|
@@ -76,7 +76,10 @@ class CLI
|
|
76
76
|
|
77
77
|
input = prompt
|
78
78
|
|
79
|
-
|
79
|
+
first_problem = Page::LENGTH * (page - 1) + 1
|
80
|
+
last_problem = Page::LENGTH * page
|
81
|
+
|
82
|
+
if input.to_i.between?(first_problem, last_problem)
|
80
83
|
problem_menu(input.to_i)
|
81
84
|
elsif input == 'n'
|
82
85
|
page_menu(page + 1)
|
@@ -113,6 +116,14 @@ class CLI
|
|
113
116
|
end
|
114
117
|
end
|
115
118
|
|
119
|
+
def search_menu
|
120
|
+
print "search: "
|
121
|
+
|
122
|
+
search_terms = gets.strip
|
123
|
+
@ac.search(search_terms)
|
124
|
+
search_results_menu
|
125
|
+
end
|
126
|
+
|
116
127
|
def search_results_menu
|
117
128
|
@ac.display_results
|
118
129
|
|
@@ -133,14 +144,6 @@ class CLI
|
|
133
144
|
end
|
134
145
|
end
|
135
146
|
|
136
|
-
def search_menu
|
137
|
-
print "search: "
|
138
|
-
|
139
|
-
search_terms = gets.strip
|
140
|
-
@ac.search(search_terms)
|
141
|
-
search_results_menu
|
142
|
-
end
|
143
|
-
|
144
147
|
end
|
145
148
|
|
146
149
|
end
|
@@ -2,22 +2,30 @@ module ProjectEulerCli
|
|
2
2
|
|
3
3
|
module Scraper
|
4
4
|
|
5
|
-
# Pulls information from the recent page to determine the total number of
|
6
|
-
# and pages.
|
5
|
+
# Pulls information from the recent page to determine the total number of
|
6
|
+
# problems and pages.
|
7
7
|
def lookup_totals
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
begin
|
9
|
+
Timeout.timeout(4) do
|
10
|
+
html = open("https://projecteuler.net/recent")
|
11
|
+
fragment = Nokogiri::HTML(html)
|
12
|
+
|
13
|
+
id_col = fragment.css('#problems_table td.id_column')
|
14
|
+
|
15
|
+
# The newest problem is the first one listed on the recent page. The ID
|
16
|
+
# of this problem will always equal the total number of problems.
|
17
|
+
Problem.total = id_col.first.text.to_i
|
18
|
+
# There are ten problems on the recent page, so the last archive problem
|
19
|
+
# can be found by subtracting 10 from the total number of problems. This
|
20
|
+
# is used to calculate the total number of pages.
|
21
|
+
last_archive_id = Problem.total - 10
|
22
|
+
Page.total = (last_archive_id - 1) / Page::LENGTH + 1
|
23
|
+
end
|
24
|
+
rescue Timeout::Error
|
25
|
+
puts "Project Euler is not responding."
|
26
|
+
|
27
|
+
exit(true)
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
31
|
# Loads in all of the problem numbers and titles from the recent page.
|
@@ -47,7 +55,7 @@ module Scraper
|
|
47
55
|
|
48
56
|
problem_links = fragment.css('#problems_table td a')
|
49
57
|
|
50
|
-
i = (page - 1) * Page::
|
58
|
+
i = (page - 1) * Page::LENGTH + 1
|
51
59
|
problem_links.each do |link|
|
52
60
|
problems[i].title = link.text
|
53
61
|
i += 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: project_euler_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ecssiah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|