blackfriday2016 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/blackfriday2016 +5 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/blackfriday2016.gemspec +29 -0
- data/config/environment.rb +8 -0
- data/lib/blackfriday2016.rb +13 -0
- data/lib/blackfriday2016/base_scraper.rb +86 -0
- data/lib/blackfriday2016/dealpage.rb +88 -0
- data/lib/blackfriday2016/vendor.rb +114 -0
- data/spec.md +6 -0
- metadata +144 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 67dcaf78f187a4e6bdfbe3d52981e298fe042546
|
|
4
|
+
data.tar.gz: 83a4045b8df91b39bf8ab3a43d2e1fe29d60878d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 962b2de9f5e20f0d270ff906bd27ff62cfc333f30c8f275444eb9965d861da9eaea4b231eafa24a6e5b8de7bf60715af6750027c7453890be4e8916ddc05d149
|
|
7
|
+
data.tar.gz: aaec0856c610d9f65385429b1c496cb76adfcb7fa17b2bc7867f837e0975c8aa5657a5eb0edbf81f489656083c6f798d54ee88798bebdf03ca84d72cc3987a49
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at cdudhat@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Chirag Dudhat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
# Black Friday 2016 Deals Cli App
|
|
3
|
+
|
|
4
|
+
Welcome to Black Friday 2016 Deals Cli App/Gem. This is a simple gem listing all the Black Friday deals offered by the stores as they are released to the public.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'blackfriday2016'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install blackfriday2016
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Follow the menu options
|
|
25
|
+
|
|
26
|
+
## Development
|
|
27
|
+
|
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
29
|
+
|
|
30
|
+
## Contributing
|
|
31
|
+
|
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/this_is_stupid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/blackfriday2016
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "blackfriday2016"
|
|
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
|
+
require "irb"
|
|
10
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = 'blackfriday2016'
|
|
7
|
+
s.version = '0.1.0'
|
|
8
|
+
s.date = '2016-11-09'
|
|
9
|
+
s.summary = "Black Friday 2016!"
|
|
10
|
+
s.description = "A simple gem listing Black Friday Deals from various stores"
|
|
11
|
+
s.authors = ["Chirag Dudhat"]
|
|
12
|
+
s.email = 'cdudhat@gmail.com'
|
|
13
|
+
s.homepage = 'https://github.com/cdudhat/blackfriday16-cli-app'
|
|
14
|
+
s.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
s.bindir = "exe"
|
|
20
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
s.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency "bundler", "~> 1.13"
|
|
24
|
+
s.add_development_dependency "rake", "~> 11.3"
|
|
25
|
+
s.add_development_dependency "rspec", "~> 0"
|
|
26
|
+
s.add_development_dependency "pry", "~> 0"
|
|
27
|
+
s.add_runtime_dependency "nokogiri", "~> 1.6"
|
|
28
|
+
s.add_runtime_dependency "colorize", "~> 0.8"
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require_relative '../config/environment'
|
|
2
|
+
|
|
3
|
+
class CommandLineInteface
|
|
4
|
+
|
|
5
|
+
def run
|
|
6
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
7
|
+
puts "Welcome to 2016 Black Friday Deal Listings!".colorize(:light_red).center(70)
|
|
8
|
+
Vendor.create_vendors
|
|
9
|
+
Vendor.display_vendors
|
|
10
|
+
puts "\n" + "-----------------------".colorize(:light_blue) + "THE-END".colorize(:light_red) + "-------------------------".colorize(:light_blue)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'pry'
|
|
4
|
+
|
|
5
|
+
class Scraper
|
|
6
|
+
|
|
7
|
+
def self.scrape_index_page(index_url)
|
|
8
|
+
index_page = Nokogiri::HTML(open(index_url))#.css("div.main").css("div.simple-vendor-grid")[1]
|
|
9
|
+
|
|
10
|
+
vendor_index = []
|
|
11
|
+
counter = 1
|
|
12
|
+
|
|
13
|
+
vendor_page = index_page.css("h3+div.simple-vendor-grid")[1..-1].css("div.line.grid-line.content-line").each do |vendor_line|
|
|
14
|
+
vendor_line.css("div.unit.tile.size1of3").each do |vendor|
|
|
15
|
+
if vendor.css("div.content-box-hd").css("a").any?
|
|
16
|
+
vendor_details = {
|
|
17
|
+
:number => counter,
|
|
18
|
+
:name => vendor.css("div.content-box-hd").css("a").text,
|
|
19
|
+
:page_url => vendor.css("div.content-box-hd").css("a").attribute("href").value,
|
|
20
|
+
:index_pagenum => (counter/10.to_f).ceil
|
|
21
|
+
}
|
|
22
|
+
counter+=1
|
|
23
|
+
else
|
|
24
|
+
break
|
|
25
|
+
end
|
|
26
|
+
vendor_index << vendor_details
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
vendor_index
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#Scrape Vendor's Deal Pages one by one as requested
|
|
33
|
+
def self.scrape_vendor_page(vendor_url)
|
|
34
|
+
deals_page = Nokogiri::HTML(open(vendor_url))
|
|
35
|
+
|
|
36
|
+
#prev_page = String.new
|
|
37
|
+
#next_page = String.new
|
|
38
|
+
full_page_deals = []
|
|
39
|
+
|
|
40
|
+
#Compile deals from the page
|
|
41
|
+
main_container = deals_page.css("div.main.browsecontent")
|
|
42
|
+
main_container.css("div.content-view.content-box.content-summary").each do |link|
|
|
43
|
+
individual_deal = []
|
|
44
|
+
deal_detail = link.css("div.unit.size3of4").css("h3.headline-xlarge a").text
|
|
45
|
+
price_detail = link.css("div.unit.size3of4").css("div.content-call-out").text.strip.gsub(/\s+/, " ")
|
|
46
|
+
price_detail = "FREE" if price_detail == ""
|
|
47
|
+
individual_deal << deal_detail << price_detail
|
|
48
|
+
full_page_deals << individual_deal
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#Collect page and page link details
|
|
52
|
+
pager = main_container.css("div.pager")
|
|
53
|
+
|
|
54
|
+
#Collect link to previous page, if it exists
|
|
55
|
+
if pager.css("a.pager-end[rel=prev]").any?
|
|
56
|
+
prev_page = pager.css("a.pager-end[rel=prev]").attribute("href").value.gsub("http://dealnews.com","")
|
|
57
|
+
else
|
|
58
|
+
prev_page = nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#Collect link to next page, if it exists
|
|
62
|
+
if pager.css("a.pager-end[rel=next]").any?
|
|
63
|
+
next_page = pager.css("a.pager-end[rel=next]").attribute("href").value.gsub("http://dealnews.com","")
|
|
64
|
+
else
|
|
65
|
+
next_page = nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#Collect current deal page number
|
|
69
|
+
page_num = pager.css("strong.pager-link.pager-current").text
|
|
70
|
+
|
|
71
|
+
#Collect Vendor name
|
|
72
|
+
name = deals_page.css("h1.section-heading").text.gsub(" Black Friday Ads","")
|
|
73
|
+
|
|
74
|
+
#Compile entire deal page Hash
|
|
75
|
+
deal_page_complete = {
|
|
76
|
+
:prev_page_link => prev_page,
|
|
77
|
+
:next_page_link => next_page,
|
|
78
|
+
:pagenum => page_num.to_i,
|
|
79
|
+
:deals => full_page_deals,
|
|
80
|
+
:vendor_name => name
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
deal_page_complete
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
|
|
3
|
+
class Dealpage
|
|
4
|
+
|
|
5
|
+
attr_accessor :prev_page_link, :next_page_link, :pagenum, :deals, :vendor_name
|
|
6
|
+
DEALS_BASE_PATH = "http://dealnews.com"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def initialize(deal_page_complete)
|
|
10
|
+
deal_page_complete.each {|key,value| self.send(("#{key}="), value)}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.create_new_dealpage(page_url)
|
|
14
|
+
deal_page_complete = Scraper.scrape_vendor_page(DEALS_BASE_PATH + page_url)
|
|
15
|
+
Dealpage.new(deal_page_complete)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.next_page
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.all
|
|
23
|
+
@@all
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.page_count
|
|
27
|
+
(self.all.count/10.to_f).ceil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#Display each deal page with deals from each page as scraped
|
|
31
|
+
def self.display_deal_details(page_url)
|
|
32
|
+
current_page = self.create_new_dealpage(page_url)
|
|
33
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
34
|
+
puts "#{current_page.vendor_name} - Deals - Page #{current_page.pagenum}:".center(55)
|
|
35
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
36
|
+
current_page.deals.each do |deal|
|
|
37
|
+
puts "# ".colorize(:light_red) + deal[0].colorize(:light_blue) + " - ".colorize(:light_red) + deal[1]
|
|
38
|
+
end
|
|
39
|
+
self.display_page_options(page_url)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.print_prev_page
|
|
43
|
+
print "| '" + "p".colorize(:light_red) + "' <<< " + "Previous Page".colorize(:light_blue) + " |"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.print_next_page
|
|
47
|
+
print "| '" + "n".colorize(:light_red) + "' >>> " + "Next Page".colorize(:light_blue) + " |"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#Display deal page options
|
|
51
|
+
def self.display_page_options(page_url)
|
|
52
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
53
|
+
current_page = self.create_new_dealpage(page_url)
|
|
54
|
+
nextpage_url = current_page.next_page_link
|
|
55
|
+
prevpage_url = current_page.prev_page_link
|
|
56
|
+
puts "Please select from options below:".colorize(:green)
|
|
57
|
+
self.print_prev_page if prevpage_url != nil
|
|
58
|
+
self.print_next_page if nextpage_url != nil
|
|
59
|
+
puts "\n" + "| '" + "s".colorize(:light_red) + "' to go back to the " + "Store Listing".colorize(:light_blue) + " |"
|
|
60
|
+
puts "| '" + "x".colorize(:light_red) + "' to " + "Exit".colorize(:light_blue) + " the program |"
|
|
61
|
+
print "\n" + "Please Enter your selection: ".colorize(:green)
|
|
62
|
+
input = gets.strip.downcase
|
|
63
|
+
if input == "n"
|
|
64
|
+
nextpage_url = self.create_new_dealpage(page_url).next_page_link
|
|
65
|
+
if nextpage_url != nil
|
|
66
|
+
self.display_deal_details(nextpage_url)
|
|
67
|
+
elsif nextpage_url == nil
|
|
68
|
+
puts "You have reached the end of Deal Listings of this Store.".colorize(:light_blue)
|
|
69
|
+
self.display_page_options(page_url)
|
|
70
|
+
end
|
|
71
|
+
elsif input == "p"
|
|
72
|
+
if prevpage_url != nil
|
|
73
|
+
self.display_deal_details(prevpage_url)
|
|
74
|
+
elsif prevpage_url == nil
|
|
75
|
+
puts "You have reached the beginning of Deal Listings of this Store.".colorize(:light_blue)
|
|
76
|
+
self.display_page_options(page_url)
|
|
77
|
+
end
|
|
78
|
+
elsif input == "s"
|
|
79
|
+
Vendor.display_vendors
|
|
80
|
+
elsif input == "x"
|
|
81
|
+
puts "Goodbye! Have a nice day.".colorize(:light_blue)
|
|
82
|
+
else
|
|
83
|
+
puts "You have entered an invalid choice. Please make a valid choice.".colorize(:light_blue)
|
|
84
|
+
self.display_page_options(page_url)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#require_relative "./base_scraper.rb"
|
|
2
|
+
#require_relative './dealpage.rb'
|
|
3
|
+
require 'pry'
|
|
4
|
+
|
|
5
|
+
class Vendor
|
|
6
|
+
attr_accessor :number, :name, :page_url, :index_pagenum
|
|
7
|
+
INDEX_BASE_PATH = "http://dealnews.com/black-friday/"
|
|
8
|
+
@@all = []
|
|
9
|
+
|
|
10
|
+
def initialize(vendor_details)
|
|
11
|
+
vendor_details.each {|key,value| self.send(("#{key}="), value)}
|
|
12
|
+
@@all << self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#Uses the Scraper class to create new vendors with all the details
|
|
16
|
+
def self.create_from_collection(vendor_index)
|
|
17
|
+
vendor_index.each do |vendor|
|
|
18
|
+
self.new(vendor)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.create_vendors
|
|
23
|
+
vendor_index = Scraper.scrape_index_page(INDEX_BASE_PATH)# + 'index.html')
|
|
24
|
+
self.create_from_collection(vendor_index)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.all
|
|
28
|
+
@@all
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#Count the total number of vendor index pages
|
|
32
|
+
def self.page_count
|
|
33
|
+
(self.all.count/10.to_f).ceil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#Returns the deal page url of a particular vendor
|
|
37
|
+
def self.return_deal_url(input)
|
|
38
|
+
return_url = nil
|
|
39
|
+
self.all.each do |vendor|
|
|
40
|
+
return_url = vendor.page_url if vendor.number == input
|
|
41
|
+
end
|
|
42
|
+
return_url
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#Returns vendor name when given a deal page url
|
|
46
|
+
def self.return_vendor_name(page_url)
|
|
47
|
+
vendor_name = nil
|
|
48
|
+
self.all.each do |vendor|
|
|
49
|
+
vendor_name = vendor.name if vendor.page_url == page_url
|
|
50
|
+
end
|
|
51
|
+
vendor_name
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.display_vendors(page_num=1)
|
|
55
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
56
|
+
puts "List of Stores - Black Friday Deals - Page #{page_num}:".center(55)
|
|
57
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
58
|
+
self.all.each do |vendor|
|
|
59
|
+
puts "#{vendor.number}. ".colorize(:light_red) + "#{vendor.name}".colorize(:light_blue) if vendor.index_pagenum == page_num
|
|
60
|
+
end
|
|
61
|
+
self.index_page_options(page_num)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.print_prev_page
|
|
65
|
+
print "| '" + "p".colorize(:light_red) + "' <<< " + "Previous Page".colorize(:light_blue) + " |"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.print_next_page
|
|
69
|
+
print "| '" + "n".colorize(:light_red) + "' >>> " + "Next Page".colorize(:light_blue) + " |"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.index_page_options(page_num=1)
|
|
73
|
+
puts "-------------------------------------------------------".colorize(:light_blue)
|
|
74
|
+
puts "Please select from options below:".colorize(:green)
|
|
75
|
+
self.print_prev_page if (page_num > 1 && page_num <= self.page_count)
|
|
76
|
+
self.print_next_page if page_num < self.page_count
|
|
77
|
+
puts "\n" + "| Store '" + "#".colorize(:light_red) + "' to " + "See Deals".colorize(:light_blue) + " from a particular Store |"
|
|
78
|
+
puts "| '" + "x".colorize(:light_red) + "' to " + "Exit".colorize(:light_blue) + " the program |"
|
|
79
|
+
print "\n" + "Please Enter your selection: ".colorize(:green)
|
|
80
|
+
input = gets.strip.downcase
|
|
81
|
+
if input == "n"
|
|
82
|
+
if page_num+1 <= self.page_count
|
|
83
|
+
self.display_vendors(page_num+1)
|
|
84
|
+
else
|
|
85
|
+
puts "You have reached the end of Store List.".colorize(:light_blue)
|
|
86
|
+
self.index_page_options(page_num)
|
|
87
|
+
end
|
|
88
|
+
elsif input == "p"
|
|
89
|
+
if page_num-1 >= 1
|
|
90
|
+
self.display_vendors(page_num-1)
|
|
91
|
+
else
|
|
92
|
+
puts "You have reached the beginning of Store List.".colorize(:light_blue)
|
|
93
|
+
self.index_page_options(page_num)
|
|
94
|
+
end
|
|
95
|
+
elsif input.include?(".")
|
|
96
|
+
puts "You have entered an invalid choice. Please make a valid choice.".colorize(:light_blue)
|
|
97
|
+
self.index_page_options(page_num)
|
|
98
|
+
elsif input.to_i > 0
|
|
99
|
+
store_num = input.to_i
|
|
100
|
+
if store_num <= self.all.count
|
|
101
|
+
Dealpage.display_deal_details(self.return_deal_url(store_num))
|
|
102
|
+
else
|
|
103
|
+
puts "You have entered an invalid Store Number. Please make a valid choice.".colorize(:light_blue)
|
|
104
|
+
self.index_page_options(page_num)
|
|
105
|
+
end
|
|
106
|
+
elsif input == "x"
|
|
107
|
+
puts "Goodbye! Have a nice day.".colorize(:light_blue)
|
|
108
|
+
else
|
|
109
|
+
puts "You have entered an invalid choice. Please make a valid choice.".colorize(:light_blue)
|
|
110
|
+
self.index_page_options(page_num)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
data/spec.md
ADDED
metadata
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: blackfriday2016
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chirag Dudhat
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-11-09 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.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '11.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '11.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: nokogiri
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.6'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.6'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: colorize
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.8'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.8'
|
|
97
|
+
description: A simple gem listing Black Friday Deals from various stores
|
|
98
|
+
email: cdudhat@gmail.com
|
|
99
|
+
executables: []
|
|
100
|
+
extensions: []
|
|
101
|
+
extra_rdoc_files: []
|
|
102
|
+
files:
|
|
103
|
+
- ".gitignore"
|
|
104
|
+
- CODE_OF_CONDUCT.md
|
|
105
|
+
- Gemfile
|
|
106
|
+
- Gemfile.lock
|
|
107
|
+
- LICENSE.txt
|
|
108
|
+
- README.md
|
|
109
|
+
- Rakefile
|
|
110
|
+
- bin/blackfriday2016
|
|
111
|
+
- bin/console
|
|
112
|
+
- bin/setup
|
|
113
|
+
- blackfriday2016.gemspec
|
|
114
|
+
- config/environment.rb
|
|
115
|
+
- lib/blackfriday2016.rb
|
|
116
|
+
- lib/blackfriday2016/base_scraper.rb
|
|
117
|
+
- lib/blackfriday2016/dealpage.rb
|
|
118
|
+
- lib/blackfriday2016/vendor.rb
|
|
119
|
+
- spec.md
|
|
120
|
+
homepage: https://github.com/cdudhat/blackfriday16-cli-app
|
|
121
|
+
licenses:
|
|
122
|
+
- MIT
|
|
123
|
+
metadata: {}
|
|
124
|
+
post_install_message:
|
|
125
|
+
rdoc_options: []
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
requirements: []
|
|
139
|
+
rubyforge_project:
|
|
140
|
+
rubygems_version: 2.6.8
|
|
141
|
+
signing_key:
|
|
142
|
+
specification_version: 4
|
|
143
|
+
summary: Black Friday 2016!
|
|
144
|
+
test_files: []
|