delegate_tracker 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d17e3ee29bad5c15ea0b13fcf926d583bf262670
4
+ data.tar.gz: abe6195a36569473541bcf34a00851f889ddd341
5
+ SHA512:
6
+ metadata.gz: ccfcd0e7e2371640c21dea84a399ff3450eae9b02186fc6d6998154cde7b372789bfb3657b7cb21c5bae32f94bb0d12a67ac31a2db373211a12687bd043029fe
7
+ data.tar.gz: 0dd82e4a0fe5a5fdfeec12d9f93a0315d2c5349c8fb25feef47ba147d996d24d018ab7376d39700880bf068d88489916cca13165ce1a8936ccba5ebd8b15004a
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at hello@jasonpaulsouthwell.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in delegate_tracker.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ delegate_tracker (0.1.1)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ mini_portile2 (2.0.0)
11
+ nokogiri (1.6.7.2)
12
+ mini_portile2 (~> 2.0.0.rc2)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.11)
20
+ delegate_tracker!
21
+ rake (~> 10.0)
22
+
23
+ BUNDLED WITH
24
+ 1.11.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 jasonpaulso
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,41 @@
1
+ # DelegateTracker
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/delegate_tracker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'delegate_tracker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install delegate_tracker
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/delegate_tracker. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "delegate_tracker"
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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/delegate_tracker'
4
+
5
+ DelegateTracker::CLI.new.call
6
+
7
+ # puts "Welcome to the Delegate Tracker!"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delegate_tracker/version'
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "delegate_tracker"
10
+ spec.version = DelegateTracker::VERSION
11
+ spec.authors = ["jasonpaulso"]
12
+ spec.email = ["hello@jasonpaulsouthwell.com"]
13
+
14
+ spec.summary = %q{A gem to connect Politico's delegate count tracker to the cl.}
15
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
16
+ spec.homepage = "https://github.com/jasonpaulso/delegate-tracker-cli-gem.git"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
20
+ # delete this section to allow pushing this gem to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = ["bin"]
29
+ spec.executables = ["delegate-tracker"]
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_dependency "nokogiri"
35
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "./delegate_tracker/version"
2
+ require_relative './delegate_tracker/cli'
3
+ require_relative './delegate_tracker/candidate_list_scraper'
4
+ require_relative './delegate_tracker/candidate'
5
+ require 'nokogiri'
6
+ require 'open-uri'
@@ -0,0 +1,27 @@
1
+ class DelegateTracker::Candidate
2
+ attr_accessor :name, :quote, :url, :delegates_earned, :delegates_needed_for_nomination
3
+
4
+ def self.create_candidate(party, profile_number)
5
+ candidate = self.new
6
+ candidate.url = Nokogiri::HTML(open(DelegateTracker::CandidateListScraper.new.get_candidate_url(party)[profile_number]))
7
+ candidate.name = candidate.url.css("h1.is-emphasized").text.strip
8
+ candidate.quote = candidate.url.css("p.quote-text").text.strip.tr('"', '')
9
+ candidate.delegates_earned = strip_to_int(candidate.url.css("span.index-text"))
10
+ candidate.delegates_needed_for_nomination = strip_to_int(candidate.url.css("span.needed-text"))
11
+ candidate_profile(candidate)
12
+ end
13
+ def self.strip_to_int(data)
14
+ data.text.strip.downcase.scan(/\d/).join('').to_i
15
+ end
16
+ def self.candidate_profile(candidate)
17
+ pronoun = candidate.name.include?("Hillary") ? "She" : "He"
18
+ puts ""
19
+ puts "#{candidate.name} has won #{candidate.delegates_earned} delegates so far."
20
+ puts ""
21
+ puts "#{pronoun} needs #{candidate.delegates_needed_for_nomination - candidate.delegates_earned} more delegates to win the nomination."
22
+ puts ""
23
+ puts "#{pronoun} is quoted to have said '#{candidate.quote}'"
24
+ puts ""
25
+ end
26
+
27
+ end
@@ -0,0 +1,29 @@
1
+ class DelegateTracker::CandidateListScraper
2
+
3
+ def candidates(party)
4
+ candidate_source = Nokogiri::HTML(open("http://www.politico.com/2016-election/results/delegate-count-tracker"))
5
+ candidate_list = candidate_source.css(".contains-#{party} .candidate-name")[0..4].css('a[href]').each_with_object({}) { |n, h| h[n.text.strip] = n['href'] }
6
+ end
7
+
8
+ def candidates_list(party)
9
+ if party == "democrat"
10
+ party_proper = "Democratic"
11
+ else
12
+ party_proper = "Republican"
13
+ end
14
+ puts "Which #{party_proper} candidate would you like to learn about?"
15
+ puts ""
16
+ candidates(party).each_with_index{|(k,v), index| puts "#{index+=1}. #{k}"}
17
+ puts "R. Random candidate"
18
+ puts "Q. Return to party selection."
19
+ end
20
+
21
+ def get_candidate_url(party)
22
+ candidates(party).each_with_index.map{ |(k,v), index| "#{v}"}
23
+ end
24
+
25
+ def count(party)
26
+ self.candidates(party).count
27
+ end
28
+
29
+ end
@@ -0,0 +1,59 @@
1
+ class DelegateTracker::CLI
2
+
3
+ def call
4
+ party_selection
5
+ goodbye
6
+ end
7
+
8
+ def prompt(message = "What would you like to do today?")
9
+ puts message
10
+ print ":> "
11
+ gets.chomp
12
+ end
13
+
14
+ def parties
15
+ puts "Welcome to the 2016 Presidential Candidate Delegate Tracker!"
16
+ puts ""
17
+ puts "Which party would you like to view?"
18
+ puts "1. Democrats"
19
+ puts "2. Republicans"
20
+ puts "Q. Quit"
21
+ end
22
+
23
+ def party_selection
24
+ party_selection = prompt(parties)
25
+ case party_selection
26
+ when "1"
27
+ candidate_selection_list("democrat")
28
+ when "2"
29
+ candidate_selection_list("republican")
30
+ end
31
+ end
32
+
33
+ def candidate_selection_list(party)
34
+ scraper = DelegateTracker::CandidateListScraper.new
35
+ until [user_selection = prompt(scraper.candidates_list(party)).downcase].include?('q')
36
+ if user_selection.to_i <= (scraper.count(party)) || user_selection == "r"
37
+ case user_selection
38
+ when "1"
39
+ DelegateTracker::Candidate.create_candidate(party, 0)
40
+ when "2"
41
+ DelegateTracker::Candidate.create_candidate(party, 1)
42
+ when "3"
43
+ DelegateTracker::Candidate.create_candidate(party, 2)
44
+ when "4"
45
+ DelegateTracker::Candidate.create_candidate(party, 3)
46
+ when "r"
47
+ DelegateTracker::Candidate.create_candidate(party, (rand 0 .. scraper.count(party)-1))
48
+ end
49
+ else
50
+ puts "Please select from the options provided."
51
+ end
52
+ end
53
+ party_selection
54
+ end
55
+ def goodbye
56
+ puts "Thanks! And don't forget to VOTE!!!"
57
+ end
58
+
59
+ end
@@ -0,0 +1,3 @@
1
+ module DelegateTracker
2
+ VERSION = "0.1.3"
3
+ end
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delegate_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - jasonpaulso
8
+ autorequire:
9
+ bindir:
10
+ - bin
11
+ cert_chain: []
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: nokogiri
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description:
57
+ email:
58
+ - hello@jasonpaulsouthwell.com
59
+ executables:
60
+ - delegate-tracker
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/delegate-tracker
72
+ - bin/setup
73
+ - delegate_tracker.gemspec
74
+ - lib/delegate_tracker.rb
75
+ - lib/delegate_tracker/candidate.rb
76
+ - lib/delegate_tracker/candidate_list_scraper.rb
77
+ - lib/delegate_tracker/cli.rb
78
+ - lib/delegate_tracker/version.rb
79
+ - pkg/delegate_tracker-0.1.0.gem
80
+ - pkg/delegate_tracker-0.1.1.gem
81
+ homepage: https://github.com/jasonpaulso/delegate-tracker-cli-gem.git
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: A gem to connect Politico's delegate count tracker to the cl.
105
+ test_files: []