blackfriday2016 0.1.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00a84ef681721ba93f8bb92b15fe16295314d9a6
4
- data.tar.gz: c4428f86079d3bbee5be8a7f8a94859f6e4b5215
3
+ metadata.gz: 3a51ed098d75df7610b32b687f5b7613f2414256
4
+ data.tar.gz: 52ca4b273a71d65508973edc0835b440e1fe7422
5
5
  SHA512:
6
- metadata.gz: 2374599ef13692cf3232295cc7ae61a61e771f4bc69294950ec31228e272dbe5ba33a3de40b28e46ad049098171f652f69ade91796c3917dace830a8ec86dcae
7
- data.tar.gz: 170680d5ea2f6a28ad2e0a66e5525994616eae8ba9254a94b4372c9c1a4e48ec88f6d0352be08bf9b2e252862012891f54fd4b6788ffffebdfbf903af83dbfa3
6
+ metadata.gz: d200ffadc846de421da8102d4f1d9d9e1a924b9544cae73faf4f49f7193f17664e5541f02681e0ddc1c76a767ef69a354d5cdd81662b8626e82b278784adbee5
7
+ data.tar.gz: eef9d9e54cf532ab099ee96a9a4cbbdde2bf4953034484ae4889932f10c492d2f619c2027573c7ab9eda9e49c9e4afdc04545350c748b3b6a5d7bf3c61666646
data/README.md CHANGED
@@ -1,27 +1,19 @@
1
1
 
2
- # Black Friday 2016 Deals Cli App
2
+ # Black Friday 2016 Deals Cli App/Gem
3
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.
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.
5
5
 
6
6
  ## Installation
7
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:
8
+ Type as shown below-
19
9
 
20
10
  $ gem install blackfriday2016
21
11
 
22
12
  ## Usage
23
13
 
24
- Follow the menu options
14
+ Type as shown below and then follow the on screen menu options-
15
+
16
+ $ blackfriday2016
25
17
 
26
18
  ## Development
27
19
 
@@ -29,7 +21,7 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
29
21
 
30
22
  ## Contributing
31
23
 
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.
24
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cdudhat/blackfriday16-cli-app. 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
25
 
34
26
  ## License
35
27
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'blackfriday2016'
7
- s.version = '0.1.1'
7
+ s.version = '0.1.2'
8
8
  s.date = '2016-11-10'
9
9
  s.summary = "Black Friday 2016!"
10
10
  s.description = "A simple gem listing Black Friday Deals from various stores"
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
19
  #s.bindir = "exe"
20
- s.executables = "blackfriday2016" #s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.executables = "blackfriday2016"
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_development_dependency "bundler", "~> 1.13"
@@ -33,12 +33,10 @@ class Scraper
33
33
  def self.scrape_vendor_page(vendor_url)
34
34
  deals_page = Nokogiri::HTML(open(vendor_url))
35
35
 
36
- #prev_page = String.new
37
- #next_page = String.new
38
36
  full_page_deals = []
39
37
 
40
38
  #Compile deals from the page
41
- main_container = deals_page.css("div.main.browsecontent")
39
+ main_container = deals_page.css("div.dynamic-pager")
42
40
  main_container.css("div.content-view.content-box.content-summary").each do |link|
43
41
  individual_deal = []
44
42
  deal_detail = link.css("div.unit.size3of4").css("h3.headline-xlarge a").text
@@ -67,9 +65,10 @@ class Scraper
67
65
 
68
66
  #Collect current deal page number
69
67
  page_num = pager.css("strong.pager-link.pager-current").text
68
+ page_num = "1" if (prev_page == nil && next_page == nil)
70
69
 
71
70
  #Collect Vendor name
72
- name = deals_page.css("h1.section-heading").text.gsub(" Black Friday Ads","")
71
+ name = deals_page.css("div.banner-tagline h1").text.gsub(" Coupons & Promo Codes for November 2016","")
73
72
 
74
73
  #Compile entire deal page Hash
75
74
  deal_page_complete = {
@@ -79,7 +78,7 @@ class Scraper
79
78
  :deals => full_page_deals,
80
79
  :vendor_name => name
81
80
  }
82
-
81
+
83
82
  deal_page_complete
84
83
  end
85
84
 
@@ -15,10 +15,6 @@ class Dealpage
15
15
  Dealpage.new(deal_page_complete)
16
16
  end
17
17
 
18
- def self.next_page
19
-
20
- end
21
-
22
18
  def self.all
23
19
  @@all
24
20
  end
@@ -27,7 +23,7 @@ class Dealpage
27
23
  (self.all.count/10.to_f).ceil
28
24
  end
29
25
 
30
- #Display each deal page with deals from each page as scraped
26
+ #Display deal page with all the deals from the page as scraped
31
27
  def self.display_deal_details(page_url)
32
28
  current_page = self.create_new_dealpage(page_url)
33
29
  puts "-------------------------------------------------------".colorize(:light_blue)
@@ -39,15 +35,37 @@ class Dealpage
39
35
  self.display_page_options(page_url)
40
36
  end
41
37
 
38
+ #Prints Previous Page indicator
42
39
  def self.print_prev_page
43
40
  print "| '" + "p".colorize(:light_red) + "' <<< " + "Previous Page".colorize(:light_blue) + " |"
44
41
  end
45
42
 
43
+ #Prints Next Page indicator
46
44
  def self.print_next_page
47
45
  print "| '" + "n".colorize(:light_red) + "' >>> " + "Next Page".colorize(:light_blue) + " |"
48
46
  end
49
47
 
50
- #Display deal page options
48
+ #Method to display next page of deals if applicable
49
+ def self.go_to_next_page(nextpage_url, page_url)
50
+ if nextpage_url != nil
51
+ self.display_deal_details(nextpage_url)
52
+ elsif nextpage_url == nil
53
+ puts "You have reached the end of Deal Listings of this Store.".colorize(:light_blue)
54
+ self.display_page_options(page_url)
55
+ end
56
+ end
57
+
58
+ #Method to display previous page of deals if applicable
59
+ def self.go_to_prev_page(prevpage_url, page_url)
60
+ if prevpage_url != nil
61
+ self.display_deal_details(prevpage_url)
62
+ elsif prevpage_url == nil
63
+ puts "You have reached the beginning of Deal Listings of this Store.".colorize(:light_blue)
64
+ self.display_page_options(page_url)
65
+ end
66
+ end
67
+
68
+ #Display deal page menu options
51
69
  def self.display_page_options(page_url)
52
70
  puts "-------------------------------------------------------".colorize(:light_blue)
53
71
  current_page = self.create_new_dealpage(page_url)
@@ -61,20 +79,9 @@ class Dealpage
61
79
  print "\n" + "Please Enter your selection: ".colorize(:green)
62
80
  input = gets.strip.downcase
63
81
  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
82
+ self.go_to_next_page(nextpage_url, page_url)
71
83
  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
84
+ self.go_to_prev_page(prevpage_url, page_url)
78
85
  elsif input == "s"
79
86
  Vendor.display_vendors
80
87
  elsif input == "x"
@@ -7,6 +7,7 @@ class Vendor
7
7
  INDEX_BASE_PATH = "http://dealnews.com/black-friday/"
8
8
  @@all = []
9
9
 
10
+ #Initializes each of the vendor attributes
10
11
  def initialize(vendor_details)
11
12
  vendor_details.each {|key,value| self.send(("#{key}="), value)}
12
13
  @@all << self
@@ -19,6 +20,7 @@ class Vendor
19
20
  end
20
21
  end
21
22
 
23
+ #Scrapes from the index page, and creates vendors
22
24
  def self.create_vendors
23
25
  vendor_index = Scraper.scrape_index_page(INDEX_BASE_PATH)# + 'index.html')
24
26
  self.create_from_collection(vendor_index)
@@ -51,6 +53,7 @@ class Vendor
51
53
  vendor_name
52
54
  end
53
55
 
56
+ #Displays list of Stores
54
57
  def self.display_vendors(page_num=1)
55
58
  puts "-------------------------------------------------------".colorize(:light_blue)
56
59
  puts "List of Stores - Black Friday Deals - Page #{page_num}:".center(55)
@@ -61,14 +64,47 @@ class Vendor
61
64
  self.index_page_options(page_num)
62
65
  end
63
66
 
67
+ #Prints Previous Page indicator
64
68
  def self.print_prev_page
65
69
  print "| '" + "p".colorize(:light_red) + "' <<< " + "Previous Page".colorize(:light_blue) + " |"
66
70
  end
67
71
 
72
+ #Prints Next Page indicator
68
73
  def self.print_next_page
69
74
  print "| '" + "n".colorize(:light_red) + "' >>> " + "Next Page".colorize(:light_blue) + " |"
70
75
  end
71
76
 
77
+ #Method to display next page of stores list if applicable
78
+ def self.go_to_next_page(page_num)
79
+ if page_num+1 <= self.page_count
80
+ self.display_vendors(page_num+1)
81
+ else
82
+ puts "You have reached the end of Store List.".colorize(:light_blue)
83
+ self.index_page_options(page_num)
84
+ end
85
+ end
86
+
87
+ #Method to display previous page of stores list if applicable
88
+ def self.go_to_prev_page(page_num)
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
+ end
96
+
97
+ #Method to display the first page of deals of a particular selected store
98
+ def self.go_to_store_deals(store_num, page_num)
99
+ if store_num <= self.all.count
100
+ Dealpage.display_deal_details(self.return_deal_url(store_num))
101
+ else
102
+ puts "You have entered an invalid Store Number. Please make a valid choice.".colorize(:light_blue)
103
+ self.index_page_options(page_num)
104
+ end
105
+ end
106
+
107
+ #Display Store List menu options
72
108
  def self.index_page_options(page_num=1)
73
109
  puts "-------------------------------------------------------".colorize(:light_blue)
74
110
  puts "Please select from options below:".colorize(:green)
@@ -79,30 +115,15 @@ class Vendor
79
115
  print "\n" + "Please Enter your selection: ".colorize(:green)
80
116
  input = gets.strip.downcase
81
117
  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
118
+ self.go_to_next_page(page_num)
88
119
  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?(".")
120
+ self.go_to_prev_page(page_num)
121
+ elsif (input.include?(".") || input.include?(",")) #To make float inputs invalid
96
122
  puts "You have entered an invalid choice. Please make a valid choice.".colorize(:light_blue)
97
123
  self.index_page_options(page_num)
98
124
  elsif input.to_i > 0
99
125
  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
126
+ self.go_to_store_deals(store_num, page_num)
106
127
  elsif input == "x"
107
128
  puts "Goodbye! Have a nice day.".colorize(:light_blue)
108
129
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackfriday2016
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chirag Dudhat