approval-ratings-cli-app 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +6 -0
- data/approval-ratings-cli-app.gemspec +26 -0
- data/bin/approval-ratings +5 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/lib/approval_ratings.rb +10 -0
- data/lib/approval_ratings/cli.rb +84 -0
- data/lib/approval_ratings/rating.rb +54 -0
- data/lib/approval_ratings/version.rb +3 -0
- data/spec.rb +6 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ebb762cbaf8f429fe4e7ede0291bd36a349b06ed
|
4
|
+
data.tar.gz: 57ca5748414b182369109750d572874a76c76d24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61676c263354ef48bc27d6bbdfe72e383bcfb5ecc2e3d0afe903ccb42667bd0e47c95e98db447d26c78eaec6310ec64804ad07fd4332dbed916add2bdd24f078
|
7
|
+
data.tar.gz: 37ddbc76a301b47246d5c38dda2ace8961e970ae1b0115b72c033c501c1a64572fea773adb448d160320fa94289852638c773f4681c24b356f88383df4cb8525
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
approval-rating-cli-app (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.3.8)
|
10
|
+
coderay (1.1.0)
|
11
|
+
crack (0.4.2)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
hashdiff (0.2.3)
|
15
|
+
method_source (0.8.2)
|
16
|
+
mini_portile (0.6.2)
|
17
|
+
nokogiri (1.6.6.2)
|
18
|
+
mini_portile (~> 0.6.0)
|
19
|
+
nokogiri (1.6.6.2-x86-mingw32)
|
20
|
+
mini_portile (~> 0.6.0)
|
21
|
+
pry (0.10.3)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.8.1)
|
24
|
+
slop (~> 3.4)
|
25
|
+
rake (10.4.2)
|
26
|
+
rspec (3.4.0)
|
27
|
+
rspec-core (~> 3.4.0)
|
28
|
+
rspec-expectations (~> 3.4.0)
|
29
|
+
rspec-mocks (~> 3.4.0)
|
30
|
+
rspec-core (3.4.0)
|
31
|
+
rspec-support (~> 3.4.0)
|
32
|
+
rspec-expectations (3.4.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.4.0)
|
35
|
+
rspec-mocks (3.4.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.4.0)
|
38
|
+
rspec-support (3.4.0)
|
39
|
+
safe_yaml (1.0.4)
|
40
|
+
slop (3.6.0)
|
41
|
+
vcr (3.0.0)
|
42
|
+
webmock (1.22.3)
|
43
|
+
addressable (>= 2.3.6)
|
44
|
+
crack (>= 0.3.2)
|
45
|
+
hashdiff
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
x86-mingw32
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (~> 1.10)
|
53
|
+
nokogiri
|
54
|
+
approval-ratings-cli-app!
|
55
|
+
pry
|
56
|
+
rake (~> 10.0)
|
57
|
+
rspec
|
58
|
+
vcr
|
59
|
+
webmock
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 nadine fischoff
|
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,32 @@
|
|
1
|
+
# Approval::Ratings::Cli::Gem
|
2
|
+
|
3
|
+
|
4
|
+
## Steps (tentative)
|
5
|
+
* find site from which to scrape
|
6
|
+
* inspect elements to see if can use it
|
7
|
+
* use structure of now playing
|
8
|
+
* iterate through td's
|
9
|
+
* using binding.pry to determine elements on which to iterate
|
10
|
+
* fix duplicates issue in list
|
11
|
+
* fix find_by_name to return duplicates
|
12
|
+
* create additional function for printing list of finding_by_number, which is now different from find_by_name because it only returns one vs potentialy > 1 for find_by_name
|
13
|
+
* fix array length sent to CLI instead of limiting the size of the list in the CLI, because the find_by_name will only return values for those on list, instead of all possible without truncating array
|
14
|
+
* publish gem
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'approval_ratings/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.authors = ["Nadine Fischoff"]
|
8
|
+
spec.email = ["nfischoff@learn.co"]
|
9
|
+
spec.description = %q{Pres Approval Ratings}
|
10
|
+
spec.summary = %q{Pres Approval Ratings}
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($\)
|
13
|
+
spec.executables = ["approval-ratings"]
|
14
|
+
spec.name = "approval-ratings-cli-app"
|
15
|
+
spec.require_paths = ["lib", "lib/approval_ratings"]
|
16
|
+
spec.version = ApprovalRatings::VERSION
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "nokogiri"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "vcr"
|
25
|
+
spec.add_development_dependency "webmock"
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "approval_ratings"
|
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,84 @@
|
|
1
|
+
require 'pry'
|
2
|
+
class ApprovalRatings::CLI
|
3
|
+
def call
|
4
|
+
start
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
puts ""
|
9
|
+
puts "************* President Trump Approval Ratings *************"
|
10
|
+
puts ""
|
11
|
+
ApprovalRatings::Rating.all.each.with_index(1) do |rating, i|
|
12
|
+
puts "#{i}. #{rating.name} on #{rating.date}"
|
13
|
+
end
|
14
|
+
puts ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_rating(rating)
|
18
|
+
rating.each do |rating|
|
19
|
+
|
20
|
+
puts ""
|
21
|
+
puts "-------------- #{rating.name} --------------"
|
22
|
+
puts "poll date"
|
23
|
+
puts rating.date
|
24
|
+
puts ""
|
25
|
+
puts "pollster grade"
|
26
|
+
puts rating.summary
|
27
|
+
puts ""
|
28
|
+
puts "approval rating"
|
29
|
+
puts rating.approval
|
30
|
+
puts ""
|
31
|
+
puts "disapproval rating"
|
32
|
+
puts rating.disapproval
|
33
|
+
puts ""
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def print_rating_i(rating)
|
38
|
+
|
39
|
+
puts ""
|
40
|
+
puts "-------------- #{rating.name} --------------"
|
41
|
+
puts "poll date"
|
42
|
+
puts rating.date
|
43
|
+
puts ""
|
44
|
+
puts "pollster grade"
|
45
|
+
puts rating.summary
|
46
|
+
puts ""
|
47
|
+
puts "approval rating"
|
48
|
+
puts rating.approval
|
49
|
+
puts ""
|
50
|
+
puts "disapproval rating"
|
51
|
+
puts rating.disapproval
|
52
|
+
puts ""
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def start
|
57
|
+
list
|
58
|
+
input = nil
|
59
|
+
while input != "exit"
|
60
|
+
puts ""
|
61
|
+
puts "What poll would you more information on, by name or number?"
|
62
|
+
puts ""
|
63
|
+
puts "Enter list to see the polls again."
|
64
|
+
puts "Enter exit to end the program."
|
65
|
+
puts ""
|
66
|
+
input = gets.strip
|
67
|
+
if input == "list"
|
68
|
+
list
|
69
|
+
elsif input.to_i == 0
|
70
|
+
if rating = ApprovalRatings::Rating.find_by_name(input)
|
71
|
+
print_rating(rating)
|
72
|
+
|
73
|
+
end
|
74
|
+
elsif input.to_i > 0
|
75
|
+
if rating = ApprovalRatings::Rating.find(input.to_i)
|
76
|
+
print_rating_i(rating)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
puts "Goodbye!!!"
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'pry'
|
2
|
+
#require 'openssl'
|
3
|
+
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
4
|
+
|
5
|
+
class ApprovalRatings::Rating
|
6
|
+
|
7
|
+
attr_accessor :name, :date, :url, :summary, :approval, :disapproval
|
8
|
+
|
9
|
+
def initialize(name = nil, date = nil, summary = nil, approval = nil, disapproval = nil)
|
10
|
+
@name = name
|
11
|
+
@date = date
|
12
|
+
@summary = summary
|
13
|
+
@approval = approval
|
14
|
+
@disapproval = disapproval
|
15
|
+
@url = 'https://projects.fivethirtyeight.com/trump-approval-ratings/'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all
|
19
|
+
@@all ||= scrape_approval_ratings
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find(id)
|
23
|
+
self.all[id-1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find_by_name(name)
|
27
|
+
self.all.find_all { |i| i.name.downcase.strip == name.downcase.strip }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.scrape_approval_ratings
|
33
|
+
doc = Nokogiri::HTML(open('https://projects.fivethirtyeight.com/trump-approval-ratings/'))
|
34
|
+
pollsters = []
|
35
|
+
doc.css("tbody tr.hidden[data-subgroup='Adults']").each do |pollster|
|
36
|
+
pollster_name = pollster.css("td.pollster a").text
|
37
|
+
pollster_date = pollster.css("td.dates").text
|
38
|
+
pollster_summary = pollster.css("div.gradeText").text
|
39
|
+
pollster_approval = pollster.at_css("td.answer.first").text
|
40
|
+
pollster_disapproval = pollster.at_css("td.answer.last").text
|
41
|
+
# puts "pollster #{pollster}"
|
42
|
+
new_pollster = new(pollster_name, pollster_date, pollster_summary, pollster_approval, pollster_disapproval)
|
43
|
+
pollsters << new_pollster unless pollsters.include?(new_pollster.name) || pollsters.size > 19
|
44
|
+
|
45
|
+
end
|
46
|
+
pollsters
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def doc
|
51
|
+
@doc ||= Nokogiri::HTML(open(self.url))
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: approval-ratings-cli-app
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nadine Fischoff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-11 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: '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: nokogiri
|
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: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Pres Approval Ratings
|
112
|
+
email:
|
113
|
+
- nfischoff@learn.co
|
114
|
+
executables:
|
115
|
+
- approval-ratings
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".rspec"
|
120
|
+
- CODE_OF_CONDUCT.md
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- approval-ratings-cli-app.gemspec
|
127
|
+
- bin/approval-ratings
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/approval_ratings.rb
|
131
|
+
- lib/approval_ratings/cli.rb
|
132
|
+
- lib/approval_ratings/rating.rb
|
133
|
+
- lib/approval_ratings/version.rb
|
134
|
+
- spec.rb
|
135
|
+
homepage:
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
- lib/approval_ratings
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.8
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Pres Approval Ratings
|
160
|
+
test_files: []
|