domestic_goods 0.1.7
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 +7 -0
- data/bin/console +14 -0
- data/bin/domestic_goods +4 -0
- data/bin/setup +8 -0
- data/lib/cli.rb +221 -0
- data/lib/domestic_goods.rb +8 -0
- data/lib/domestic_goods/american_list.rb +114 -0
- data/lib/domestic_goods/version.rb +3 -0
- metadata +109 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1567915ad9d84e852726c89e73d398f44874454d
|
|
4
|
+
data.tar.gz: fc9d98ccfa41cd2c13e1a82a2ff39df0d44eec2a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3adc8f6a5f149fe7bb9c5fb4687940549f53b06f1b5ddbe89fe67f1387ef5f45b51b91e5cbd5f1ee90ffac0fcd99bfbf754a19ab122c0e92f4f7c4e04657888c
|
|
7
|
+
data.tar.gz: 98333c2d0fa2f3c878289cac9ef3fda481b27e91ec17a8f8d1b7887514b29c8255d458d09b0165505a400ccaa7e49d4cc5abad9fd4909ddf8686529b3fa612d1
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "domestic_goods"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/domestic_goods
ADDED
data/bin/setup
ADDED
data/lib/cli.rb
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
class DomesticGoods::CLI
|
|
2
|
+
|
|
3
|
+
def call
|
|
4
|
+
prompt
|
|
5
|
+
see_ya
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
#attr_reader :input
|
|
9
|
+
|
|
10
|
+
def prompt
|
|
11
|
+
puts "\n"
|
|
12
|
+
puts "Welcome to Domestic Goods, a directory of American-made companies. Would you like to search brands:"
|
|
13
|
+
puts "\n"+"1. Randomly\n2. By Category"
|
|
14
|
+
input = gets.strip.downcase
|
|
15
|
+
case input
|
|
16
|
+
when "1" || "1." || "randomly" || "random"
|
|
17
|
+
assorted_goods
|
|
18
|
+
when "2" || "2." || "by category"
|
|
19
|
+
category_selector
|
|
20
|
+
when "exit"
|
|
21
|
+
hard_out
|
|
22
|
+
else
|
|
23
|
+
puts "Sorry, I didn't catch that. Please enter either 1 or 2."
|
|
24
|
+
prompt
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def assorted_goods
|
|
29
|
+
DomesticGoods::AmericanList.assorted_scraper
|
|
30
|
+
@assorted_companies = DomesticGoods::AmericanList.assorted
|
|
31
|
+
input = nil
|
|
32
|
+
answer = nil
|
|
33
|
+
puts "How many companies would you like to see? 5 or 10? Type exit to leave."
|
|
34
|
+
input = gets.strip.downcase
|
|
35
|
+
case input
|
|
36
|
+
when "5"
|
|
37
|
+
five_assorted_companies
|
|
38
|
+
when "10"
|
|
39
|
+
ten_assorted_companies
|
|
40
|
+
when "exit"
|
|
41
|
+
hard_out
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def five_assorted_companies
|
|
47
|
+
@assorted_companies.shuffle![0..4].map.with_index(1) do |company,index|
|
|
48
|
+
puts "\n" + "#{index}. Company: #{company[:name]}\n Category: #{company[:category]}"
|
|
49
|
+
end
|
|
50
|
+
assorted_companies_prompt(5,4)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def ten_assorted_companies
|
|
54
|
+
@assorted_companies.shuffle![0..9].map.with_index(1) do |company,index|
|
|
55
|
+
puts "\n" + "#{index}. Company: #{company[:name]}\n Category: #{company[:category]}"
|
|
56
|
+
end
|
|
57
|
+
assorted_companies_prompt(10,9)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def assorted_companies_prompt(companies,index_count)
|
|
63
|
+
puts "\n" + "-Learn more about a company above by entering its number(1-#{companies})"
|
|
64
|
+
puts "-See more companies by entering 'more'"
|
|
65
|
+
puts "-Go back to main menu by entering 'menu'"
|
|
66
|
+
puts "-Exit by entering 'exit'"
|
|
67
|
+
answer = gets.strip.downcase
|
|
68
|
+
|
|
69
|
+
counter = companies
|
|
70
|
+
|
|
71
|
+
while counter > 0
|
|
72
|
+
if answer == counter.to_s
|
|
73
|
+
puts "Company: #{@assorted_companies[counter - 1][:name]}\nLocation: #{@assorted_companies[counter - 1][:location]}\nWebsite: #{@assorted_companies[counter - 1][:url]} "
|
|
74
|
+
see_more?(index_count)
|
|
75
|
+
end
|
|
76
|
+
counter-=1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if answer == "more"
|
|
80
|
+
assorted_goods
|
|
81
|
+
elsif answer == "menu"
|
|
82
|
+
prompt
|
|
83
|
+
elsif answer == "exit"
|
|
84
|
+
hard_out
|
|
85
|
+
else
|
|
86
|
+
puts "Sorry, I didn't get that. You can type 'more', 'menu', 'exit', or the number of the company you're interested in."
|
|
87
|
+
assorted_companies_prompt(companies, index_count)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def see_more?(index)
|
|
93
|
+
puts "\n" + "Would you like to 1. Go back 2. See more companies 3. Main menu 4. Exit"
|
|
94
|
+
input = gets.strip.downcase
|
|
95
|
+
case input
|
|
96
|
+
when "1" || "back"
|
|
97
|
+
@assorted_companies[0..index].map.with_index(1) do |company,index|
|
|
98
|
+
puts "\n" + "#{index}. Company: #{company[:name]}\nCategory: #{company[:category]}"
|
|
99
|
+
end
|
|
100
|
+
if index == 4
|
|
101
|
+
assorted_companies_prompt(5,4)
|
|
102
|
+
elsif index == 9
|
|
103
|
+
assorted_companies_prompt(10,9)
|
|
104
|
+
end
|
|
105
|
+
when "2" || "see more"
|
|
106
|
+
assorted_goods
|
|
107
|
+
when "3" || "menu"
|
|
108
|
+
prompt
|
|
109
|
+
when "4" || "exit"
|
|
110
|
+
hard_out
|
|
111
|
+
else
|
|
112
|
+
puts "Sorry, I didn't get that."
|
|
113
|
+
see_more?(index)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def category_selector
|
|
118
|
+
puts "Which kind of companies would you like to see?"
|
|
119
|
+
puts "\n" + "1. Women's Apparel\n2. Men's Apparel\n3. Home Goods\n4. Gifts"
|
|
120
|
+
input = gets.strip.downcase
|
|
121
|
+
case input
|
|
122
|
+
when "1" || "1." || "women" || "women's apparel" || "womens apparel"
|
|
123
|
+
DomesticGoods::AmericanList.women_clothing_scraper
|
|
124
|
+
women_clothing
|
|
125
|
+
when "2" || "2." || "men" || "men's apparel" || "mens apparel"
|
|
126
|
+
DomesticGoods::AmericanList.men_clothing_scraper
|
|
127
|
+
men_clothing
|
|
128
|
+
when "3" || "3." || "home" || "home goods"
|
|
129
|
+
DomesticGoods::AmericanList.home_goods_scraper
|
|
130
|
+
home_goods
|
|
131
|
+
when "4" || "4." || "gifts"
|
|
132
|
+
DomesticGoods::AmericanList.gifts_scraper
|
|
133
|
+
gifts
|
|
134
|
+
when "exit"
|
|
135
|
+
hard_out
|
|
136
|
+
else
|
|
137
|
+
puts "Sorry, I didn't catch that."
|
|
138
|
+
category_selector
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def women_clothing
|
|
143
|
+
product_list = DomesticGoods::AmericanList.womens_clothing
|
|
144
|
+
print_info(product_list)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def men_clothing
|
|
148
|
+
product_list = DomesticGoods::AmericanList.mens_clothing
|
|
149
|
+
print_info(product_list)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def home_goods
|
|
153
|
+
product_list = DomesticGoods::AmericanList.home_goods
|
|
154
|
+
print_info(product_list)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def gifts
|
|
158
|
+
product_list = DomesticGoods::AmericanList.gifts
|
|
159
|
+
print_info(product_list)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def print_info(product_list)
|
|
164
|
+
list = product_list
|
|
165
|
+
input = nil
|
|
166
|
+
answer = nil
|
|
167
|
+
puts "How many different companies would you like to see? 5 or 10? Type exit to leave."
|
|
168
|
+
input = gets.strip.downcase
|
|
169
|
+
case input
|
|
170
|
+
when "5"
|
|
171
|
+
list.shuffle[0..4].each do |company|
|
|
172
|
+
|
|
173
|
+
puts "\n" + "Company: #{company[:name]}\nDescription: #{company[:description]}\nWebsite: #{company[:url]}"
|
|
174
|
+
end
|
|
175
|
+
puts "\n" + "What would you like to do now? 1. See more 2. Go to main menu or 3. exit?"
|
|
176
|
+
answer = gets.strip.downcase
|
|
177
|
+
if answer == "1" || answer == "more" || answer == "see more"
|
|
178
|
+
print_info(product_list)
|
|
179
|
+
elsif answer == "2" || answer == "menu" || answer == "2."
|
|
180
|
+
prompt
|
|
181
|
+
elsif answer == "3" || answer == "exit"
|
|
182
|
+
hard_out
|
|
183
|
+
end
|
|
184
|
+
when "10"
|
|
185
|
+
list.shuffle[0..9].each do |company|
|
|
186
|
+
puts "\n" + "Company: #{company[:name]}\nDescription: #{company[:description]}\nWebsite: #{company[:url]}"
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
puts "\n"
|
|
190
|
+
puts "What would you like to do now? 1. See more 2. Go to main menu or 3. exit?"
|
|
191
|
+
answer = gets.strip.downcase
|
|
192
|
+
if answer == "1" || answer == "more" || answer == "see more"
|
|
193
|
+
print_info(product_list)
|
|
194
|
+
elsif answer == "2" || answer == "menu" || answer == "2."
|
|
195
|
+
prompt
|
|
196
|
+
elsif answer == "3" || answer == "exit"
|
|
197
|
+
hard_out
|
|
198
|
+
end
|
|
199
|
+
when "exit"
|
|
200
|
+
hard_out
|
|
201
|
+
else
|
|
202
|
+
puts "Sorry, I didn't get that."
|
|
203
|
+
print_info(product_list)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def see_ya
|
|
212
|
+
puts "Thanks for stopping by. See you next time."
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def hard_out
|
|
216
|
+
puts "Thanks for stopping by. See you next time."
|
|
217
|
+
exit
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
class DomesticGoods::AmericanList
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :url, :category, :location, :description
|
|
4
|
+
|
|
5
|
+
@assorted = []
|
|
6
|
+
@womens_clothes = []
|
|
7
|
+
@mens_clothes = []
|
|
8
|
+
@home_goods = []
|
|
9
|
+
@gifts = []
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def self.assorted_scraper
|
|
13
|
+
doc = Nokogiri::HTML(open("http://www.acontinuouslean.com/the-american-list/"))
|
|
14
|
+
|
|
15
|
+
doc.css("div.brands p").each do |company|
|
|
16
|
+
h = {
|
|
17
|
+
:name => company.search("a").text,
|
|
18
|
+
:url => company.search("a").attribute("href").value,
|
|
19
|
+
:location => company.text.split(" — ")[1]
|
|
20
|
+
}
|
|
21
|
+
if company.text.split(" — ")[2] == nil || company.text.split(" — ")[2] == "" || company.text.split(" — ")[2] == " "
|
|
22
|
+
h[:category] = "miscellaneous"
|
|
23
|
+
else
|
|
24
|
+
h[:category] = company.text.split(" — ")[2]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@assorted << h
|
|
28
|
+
end
|
|
29
|
+
@assorted
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.assorted
|
|
33
|
+
@assorted
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def self.women_clothing_scraper
|
|
38
|
+
women_clothing = []
|
|
39
|
+
scrape_help("http://madeinusachallenge.com/womens-clothing-made-in-usa/", women_clothing)
|
|
40
|
+
@womens_clothes = women_clothing
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.womens_clothing
|
|
44
|
+
@womens_clothes
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.men_clothing_scraper
|
|
48
|
+
mens_clothes = []
|
|
49
|
+
scrape_help("http://madeinusachallenge.com/mens-clothing-made-in-usa/", mens_clothes)
|
|
50
|
+
@mens_clothes = mens_clothes
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.mens_clothing
|
|
54
|
+
@mens_clothes
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.home_goods_scraper
|
|
58
|
+
home_goods = []
|
|
59
|
+
scrape_help("http://madeinusachallenge.com/home-and-decor-made-in-usa/", home_goods)
|
|
60
|
+
@home_goods = home_goods
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.home_goods
|
|
64
|
+
@home_goods
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.gifts_scraper
|
|
68
|
+
gifts = []
|
|
69
|
+
scrape_help("http://madeinusachallenge.com/gifts-made-in-usa/",gifts)
|
|
70
|
+
@gifts = gifts
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.gifts
|
|
74
|
+
@gifts
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def self.scrape_help(link, array)
|
|
79
|
+
doc = Nokogiri::HTML(open(link))
|
|
80
|
+
search = doc.search("div.entry-content")
|
|
81
|
+
|
|
82
|
+
companies = search.css('p')
|
|
83
|
+
links = search.css('p').css("a[target='_blank']")
|
|
84
|
+
|
|
85
|
+
companies[2..-1].each do |company|
|
|
86
|
+
|
|
87
|
+
name = company.css('a').text
|
|
88
|
+
if company.css('a').attribute('href') == nil
|
|
89
|
+
company.attribute('href').value = "http://madeinusachallenge.com"
|
|
90
|
+
end
|
|
91
|
+
url = company.css("a").attribute("href").value
|
|
92
|
+
description = company.text.split(" – ")[1]
|
|
93
|
+
|
|
94
|
+
if description == "" || description == " " || description == nil
|
|
95
|
+
description = "not provided"
|
|
96
|
+
end
|
|
97
|
+
# if url.attribute('href').value == nil
|
|
98
|
+
# url.attribute('href').value = "http://madeinusachallenge.com"
|
|
99
|
+
# end
|
|
100
|
+
|
|
101
|
+
h = {
|
|
102
|
+
:name => name,
|
|
103
|
+
:url => url,
|
|
104
|
+
:description => description
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
array << h
|
|
108
|
+
end
|
|
109
|
+
array
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: domestic_goods
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.7
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ben Norris
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-07-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.12'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: nokogiri
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Browse through American-made companies randomly or by categories, including
|
|
70
|
+
women's apparel, men's apparel, home goods, and gifts.
|
|
71
|
+
email:
|
|
72
|
+
- bennorris07@gmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- domestic_goods
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- bin/console
|
|
79
|
+
- bin/domestic_goods
|
|
80
|
+
- bin/setup
|
|
81
|
+
- lib/cli.rb
|
|
82
|
+
- lib/domestic_goods.rb
|
|
83
|
+
- lib/domestic_goods/american_list.rb
|
|
84
|
+
- lib/domestic_goods/version.rb
|
|
85
|
+
homepage: https://github.com/bennorris/domestic_goods-cli-gem
|
|
86
|
+
licenses:
|
|
87
|
+
- MIT
|
|
88
|
+
metadata: {}
|
|
89
|
+
post_install_message:
|
|
90
|
+
rdoc_options: []
|
|
91
|
+
require_paths:
|
|
92
|
+
- lib
|
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
requirements: []
|
|
104
|
+
rubyforge_project:
|
|
105
|
+
rubygems_version: 2.5.1
|
|
106
|
+
signing_key:
|
|
107
|
+
specification_version: 4
|
|
108
|
+
summary: A gem to help navigate you toward American-made goods.
|
|
109
|
+
test_files: []
|