poll_tracker 0.1.4 → 0.1.6

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: d3bd6e3fcf6f10287b2f91ad9083fbaeab807a9c
4
- data.tar.gz: dca6b3d2c31983cd427c70e1b173da938b1f69be
3
+ metadata.gz: ab0442ccc7173dbd6fcfc2ce30d71de04d1cc69d
4
+ data.tar.gz: dd9499aa7956da92acc20cd85c089a74f2ec58d2
5
5
  SHA512:
6
- metadata.gz: 401d8057306ff662e62c5ba2fc11b725170e1decd82a9cd6ec8351fd07fe7a3c37d893f02f7301a42280d5d3b73bb56ba8301ec25ee48761509a5ceede77b02f
7
- data.tar.gz: 3713d964e949ce6922a2d76513f9030627ecc78dbfbb4c7d744b3bbef74bb18912f7efd6146326bfe240ac040ef803ea2b13b59967119bd9fc70ab0a2479b010
6
+ metadata.gz: 0f848111c74d0fdc647fd422fffcf0234a46d7ef375c7890a61cf6bbe89ebc36f720634afcb57fb8d3969acf24dd6e0a242532ab54ff963a3fdd06660c01bdab
7
+ data.tar.gz: 4bdcabc538cb3f4d983f605d67a28f96ec6472a32a9946a126af5ed106870f6fdb1c2f29f62309a27b617a5a82edb24cd9249d5e9bb8c113c4d7c0a73a95bc66
data/README.md CHANGED
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install poll_tracker
19
+ $ gem install poll_tracker
20
20
 
21
21
  ## Usage
22
22
 
data/bin/poll_tracker CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "poll_tracker"
3
+ # require "bundler/setup"
4
+ require_relative "../lib/poll_tracker"
5
5
 
6
6
 
7
7
  PollTracker::CLI.new.call
8
8
 
9
-
@@ -3,26 +3,16 @@ class PollTracker::CLI
3
3
 
4
4
  def call
5
5
  welcome
6
+ show_score(PollTracker::Scraper.avg_results_hash)
7
+ menu
8
+ list_polls
9
+ show_poll
6
10
  end
7
11
 
8
- def welcome
9
- input = nil
10
- puts "***********POLL TRACKER 2016!! TRUMP vs CLINTON!!***********".white.on_light_red
11
- puts "*****************THE SHAMING OF AMERICA!!!!*****************".white.on_light_red
12
- puts ""
13
- sleep(1.5 )
14
- puts "----Hello! I am Poll Tracker! I can show you many polls.----".blue.on_light_white
15
- puts "----Currently, the average of more than 350 polls shows:----".blue.on_light_white
16
- puts ""
17
- sleep(1.5)
18
- score = PollTracker::Scraper.avg_results_hash
19
- puts "*****HILLARY CLINTON***** =====> #{score[:clinton]}%**********************".light_white.on_light_blue.underline
20
- puts "*****DONALD TRUMP?******* =====> #{score[:trump]}%*********** Seriously?".light_white.on_light_blue
21
- puts ""
22
- sleep(1.5)
12
+ def menu
23
13
  puts "Type 'YesHillary' or 'NeverTrump' to see a list of the 25 most recent polls."
24
14
  puts "Type 'exit' if this makes you sick and want to leave. PollTracker understands."
25
-
15
+ input = nil
26
16
  while input != "exit"
27
17
  input = gets.strip.downcase
28
18
 
@@ -38,6 +28,25 @@ class PollTracker::CLI
38
28
  end
39
29
  end
40
30
 
31
+ def welcome
32
+ puts "***********POLL TRACKER 2016!! TRUMP vs CLINTON!!***********".white.on_light_red
33
+ puts "*****************THE SHAMING OF AMERICA!!!!*****************".white.on_light_red
34
+ puts ""
35
+ sleep(1.5 )
36
+ puts "----Hello! I am Poll Tracker! I can show you many polls.----".blue.on_light_white
37
+ puts "----Currently, the average of more than 350 polls shows:----".blue.on_light_white
38
+ puts ""
39
+ sleep(1.5)
40
+ end
41
+
42
+ def show_score(score)
43
+ binding.pry
44
+ puts "*****HILLARY CLINTON***** =====> #{score.clinton}%**********************".light_white.on_light_blue.underline
45
+ puts "*****DONALD TRUMP?******* =====> #{score.trump}%*********** Seriously?".light_white.on_light_blue
46
+ puts ""
47
+ sleep(1.5)
48
+ end
49
+
41
50
 
42
51
  def list_polls
43
52
  puts PollTracker::Scraper.poll_names_index
@@ -1,6 +1,17 @@
1
1
  require 'pry'
2
2
  require 'nokogiri'
3
3
  require 'open-uri'
4
+
5
+ class PollTracker::Score
6
+
7
+ attr_accessor :trump, :clinton
8
+
9
+ def initialize(hash)
10
+ @trump = hash[:trump]
11
+ @clinton = hash[:clinton]
12
+ end
13
+
14
+ end
4
15
 
5
16
 
6
17
  class PollTracker::Scraper
@@ -8,22 +19,14 @@ class PollTracker::Scraper
8
19
  attr_accessor :poll
9
20
 
10
21
  def self.scrape_page
11
- doc = Nokogiri::HTML(open("http://elections.huffingtonpost.com/pollster/2016-general-election-trump-vs-clinton"))
22
+ @@doc ||= Nokogiri::HTML(open("http://elections.huffingtonpost.com/pollster/2016-general-election-trump-vs-clinton"))
12
23
  end
13
24
 
14
25
  def self.avg_results_hash
15
- results = []
16
- final_results = {}
17
- clinton = scrape_page.css("ul#chart-choice-select li label.checked span.value").first.text.gsub("%", "").to_f
18
- results << clinton
19
- trump = scrape_page.css("ul#chart-choice-select li label.checked span.value").last.text.gsub("%", "").to_f
20
- results << trump
21
- results[0].to_i
22
- results[1].to_i
23
- results
24
- final_results[:clinton] = results.first
25
- final_results[:trump] = results.last
26
- final_results
26
+ PollTracker::Score.new({
27
+ clinton: scrape_page.css("ul#chart-choice-select li label.checked span.value").first.text.gsub("%", "").to_f,
28
+ trump: scrape_page.css("ul#chart-choice-select li label.checked span.value").last.text.gsub("%", "").to_f
29
+ })
27
30
  end
28
31
 
29
32
  def self.result_helper
@@ -51,7 +54,7 @@ class PollTracker::Scraper
51
54
  def self.trump_results
52
55
  clinton = []
53
56
  trump = []
54
- trump, @clinton = all_results.each_with_index.partition { |v| v[1].even?}.map{ |v| v.map{ |v| v[0] }}
57
+ trump, clinton = all_results.each_with_index.partition { |v| v[1].even?}.map{ |v| v.map{ |v| v[0] }}
55
58
  trump
56
59
  end
57
60
 
@@ -1,3 +1,3 @@
1
- module PollTracker
2
- VERSION = "0.1.4"
1
+ module PollTracker
2
+ VERSION = "0.1.6"
3
3
  end