marvel_101 0.3.0 → 0.4.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/marvel_101/character.rb +5 -2
- data/lib/marvel_101/cli.rb +11 -7
- data/lib/marvel_101/scraper.rb +3 -2
- data/lib/marvel_101/topic.rb +17 -2
- data/lib/marvel_101/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 941d8e0298abee9dafad8888b09fd5275f50dafb
|
4
|
+
data.tar.gz: 39a7e6ab9825202c70462fbf0bd7310f84c2b3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c348c7475488c726428c7c369a172feb7dd568a3aaecf43188428893df0319b6d1a013db4ebd491f72f9ba3975bd16ab19bb2fb7ded7c8d44984c9a73a0f8a
|
7
|
+
data.tar.gz: efc292eb19f5c863b8a59f211daeb151a2aee4a3b8eea4736cc1c6b89efe40f968e888e6e2b0ec5648170399f135a11b784263704c767d9efc55fab4d0616c63
|
data/lib/marvel_101/character.rb
CHANGED
@@ -16,8 +16,11 @@ class Marvel101::Character < Marvel101::Topic
|
|
16
16
|
|
17
17
|
def display_details
|
18
18
|
DETAIL_ORDER.each do |type|
|
19
|
-
|
20
|
-
|
19
|
+
if details.include?(type)
|
20
|
+
title = type.to_s.split("_").join(" ").upcase
|
21
|
+
format_output("#{title}: #{details[type]}")
|
22
|
+
puts "" if "#{title}: #{details[type]}".size > 60
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
data/lib/marvel_101/cli.rb
CHANGED
@@ -10,6 +10,8 @@ class Marvel101::CLI
|
|
10
10
|
["The Women of Marvel", "list/996/women_of_marvel"]
|
11
11
|
]
|
12
12
|
|
13
|
+
LINE_LEN = 80
|
14
|
+
|
13
15
|
def call
|
14
16
|
puts "\nWelcome to Marvel 101!"
|
15
17
|
main_menu
|
@@ -19,6 +21,7 @@ class Marvel101::CLI
|
|
19
21
|
display_main
|
20
22
|
print ">> "
|
21
23
|
input = gets.chomp.downcase
|
24
|
+
|
22
25
|
if input.to_i.between?(1, STARTING_PAGES.size)
|
23
26
|
name, url = STARTING_PAGES[input.to_i - 1]
|
24
27
|
topic_menu(Marvel101::List.find_or_create_by_name(name, SOURCE + url))
|
@@ -34,6 +37,7 @@ class Marvel101::CLI
|
|
34
37
|
display_topic(topic)
|
35
38
|
print ">> "
|
36
39
|
input = gets.chomp.downcase
|
40
|
+
|
37
41
|
case input
|
38
42
|
when "101","wiki" then open_link("url_#{input}".to_sym, topic)
|
39
43
|
when "source" then open_link(:url, topic)
|
@@ -48,19 +52,19 @@ class Marvel101::CLI
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def display_main
|
51
|
-
puts "\n" + "-" *
|
55
|
+
puts "\n" + "-" * LINE_LEN
|
52
56
|
puts "Here are your primary options:"
|
53
57
|
STARTING_PAGES.each.with_index(1) {|page, idx| puts "#{idx}. #{page[0]}!"}
|
54
|
-
puts "-" *
|
58
|
+
puts "-" * LINE_LEN
|
55
59
|
puts "You can also enter (E)xit to... exit"
|
56
60
|
puts "Select a number from the options above and we'll get started!"
|
57
61
|
end
|
58
62
|
|
59
63
|
def display_topic(topic)
|
60
|
-
break_len = (
|
61
|
-
puts "\n" + "-" * break_len + "#{topic.name}" + "-" * break_len
|
64
|
+
break_len = (LINE_LEN - topic.name.size) / 2.0
|
65
|
+
puts "\n" + "-" * break_len.floor + "#{topic.name}" + "-" * break_len.ceil
|
62
66
|
topic.display
|
63
|
-
puts "-" *
|
67
|
+
puts "-" * LINE_LEN
|
64
68
|
options_message(topic)
|
65
69
|
end
|
66
70
|
|
@@ -80,8 +84,8 @@ class Marvel101::CLI
|
|
80
84
|
puts "Type (T)eam to return to #{topic.team.name} menu" if topic.has_team?
|
81
85
|
end
|
82
86
|
|
83
|
-
def error(
|
87
|
+
def error(topic)
|
84
88
|
puts "\nSorry, that wasn't a valid option. Let's try again."
|
85
|
-
|
89
|
+
topic == "main" ? main_menu : topic_menu(topic)
|
86
90
|
end
|
87
91
|
end
|
data/lib/marvel_101/scraper.rb
CHANGED
@@ -47,7 +47,8 @@ class Marvel101::Scraper
|
|
47
47
|
def get_description
|
48
48
|
info = doc.css("div.featured-item-desc p:nth-child(2)").text
|
49
49
|
unless info.strip.empty?
|
50
|
-
|
50
|
+
info = info.gsub(/\r?\n\s*([ml][oe][rs][es])?/," ").strip
|
51
|
+
topic.description = info.gsub("â", "\'").gsub("Â", "")
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -69,7 +70,7 @@ class Marvel101::Scraper
|
|
69
70
|
detail = raw_detail.css("strong").text.downcase.strip.split(" ").join("_")
|
70
71
|
info = raw_detail.css("p:last-child span").text.strip
|
71
72
|
info = raw_detail.css("p:last-child").text if info.empty?
|
72
|
-
topic.details[detail.to_sym] = info
|
73
|
+
topic.details[detail.to_sym] = info.gsub("â", "\'").gsub("Â", "")
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
data/lib/marvel_101/topic.rb
CHANGED
@@ -2,6 +2,8 @@ class Marvel101::Topic
|
|
2
2
|
|
3
3
|
attr_accessor :name, :description, :urls, :scraped
|
4
4
|
|
5
|
+
LINE_LEN = 80
|
6
|
+
|
5
7
|
@@all = []
|
6
8
|
|
7
9
|
def initialize(name, url)
|
@@ -18,17 +20,30 @@ class Marvel101::Topic
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def display_description
|
21
|
-
|
23
|
+
if description
|
24
|
+
format_output("DESCRIPTION: #{description}")
|
25
|
+
puts "" if "DESCRIPTION: #{description}".size > 60
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def display_links
|
25
30
|
puts "" if urls.size > 1
|
26
31
|
["wiki", "101"].each do |url|
|
27
|
-
output = "Marvel #{url} available! Type '#{url}' to open in browser"
|
32
|
+
output = "*Marvel #{url} available! Type '#{url}' to open in browser*"
|
28
33
|
puts output if urls.include?("url_#{url}".to_sym)
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
37
|
+
def format_output(text)
|
38
|
+
i = LINE_LEN
|
39
|
+
while i < text.size
|
40
|
+
line_break = text[0..i].rindex(" ")
|
41
|
+
puts text[i - LINE_LEN...line_break]
|
42
|
+
i = line_break + LINE_LEN + 1
|
43
|
+
end
|
44
|
+
puts text[i - LINE_LEN..-1]
|
45
|
+
end
|
46
|
+
|
32
47
|
def takes_input?
|
33
48
|
list? || (team? && !members.empty?)
|
34
49
|
end
|
data/lib/marvel_101/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marvel_101
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Buchheim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|