TopBoardGames 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 168c90ae5157371ea054ec69c197874af0b9aec0
4
+ data.tar.gz: a86a9415f9b2d2d10da0aff72f963019ba535c00
5
+ SHA512:
6
+ metadata.gz: 4e374b182a45697c588f6ffcd5610a73bcb1ea0ca4db35d72498e3269f61706d0bd3abec56b0df30b157401f06efa8790633766357ad64dcdbbc5aa79097f063
7
+ data.tar.gz: 5c975ec302061a33c986cc1dcce5a8c86b737faf89229d47320ce232f4a07849c44ab3d64356d77275f60563dfe079cae9a66d2fa6f85f0807aa5805b09a4200
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.4
@@ -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 jsesteves91@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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in TopBoardGames.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 johanesteves
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.
@@ -0,0 +1,41 @@
1
+ # TopBoardGames
2
+
3
+ Welcome to the Top BoardGames Gem. This gem will allow you to view the current top 100 boardgames on <strong>BoardGameGeek.com</strong>. You will be not only view the top 100, but also view more detailed information about a particular boardgame.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'TopBoardGames'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install TopBoardGames
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johanesteves/TopBoardGames. 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the TopBoardGames project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/johanesteves/TopBoardGames/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
Binary file
Binary file
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "TopBoardGames/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "TopBoardGames"
8
+ spec.version = TopBoardGames::VERSION
9
+ spec.authors = ["johanesteves"]
10
+ spec.email = ["jsesteves91@gmail.com"]
11
+
12
+ spec.summary = "Returns list of top 100 boardgames from www.boardgamegeek.com"
13
+ spec.description = "Returns list of top 100 boardgames from www.boardgamegeek.com, also allows to get boardgame description"
14
+ spec.homepage = "https://github.com/johanesteves"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against "
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "nokogiri"
38
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "TopBoardGames"
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(__FILE__)
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ #require "TopBoardGames"
5
+ require_relative '../lib/TopBoardGames'
6
+
7
+ TopBoardGames::CLI.new.cal
@@ -0,0 +1,10 @@
1
+ require 'nokogiri'
2
+ require 'pry'
3
+ require 'open-uri'
4
+
5
+ require_relative "./TopBoardGames/version"
6
+ require_relative "./TopBoardGames/cli"
7
+ require_relative "./TopBoardGames/game"
8
+ require_relative "./TopBoardGames/scraper"
9
+
10
+
@@ -0,0 +1,73 @@
1
+ class TopBoardGames::CLI
2
+
3
+ def call
4
+ TopBoardGames::Scraper.new.make_boardgames
5
+ start
6
+ end
7
+
8
+ def start
9
+ puts "", "Greetings! Here you will be able to see a list of the top 100 boardgames", ""
10
+ game_list
11
+ nav_menu
12
+ end
13
+
14
+ def list_boardgames(input)
15
+ @boardgames = TopBoardGames::Game.all
16
+ @boardgames[input].each do |game|
17
+ puts "#{game.rank}.".ljust(5)+"#{game.title}"
18
+ end
19
+ end
20
+
21
+ def game_list
22
+ puts " (1) (2) (3) (4) (5)"
23
+ puts "01-20 --- 21-40 --- 41-60 --- 61-80 --- 81-100"
24
+ puts "","Enter the list you would like to see:"
25
+ input = gets.strip.downcase
26
+ inputs = {1 => [1,20], 2 => [21, 40], 3 => [41, 60], 4 => [61, 80], 5 => [81,100]}
27
+
28
+ if input.to_i > 0
29
+ puts "","TOP BOARDGAMES: #{inputs[input.to_i][0]}-#{inputs[input.to_i][1]}"
30
+ puts "========================================================="
31
+ list_boardgames((inputs[input.to_i][0])-1..(inputs[input.to_i][1])-1) # list_boardgames(0..19)
32
+ puts "========================================================="
33
+ puts "", "Enter boardgame number you wish to view", "Enter '[m]enu' to return the main menu", "Enter '[e]xit' to quit program" ,"" ,"Enter your selection:"
34
+ end
35
+ #abort("Goodbye!!") if ["exit", "e"].include?(input)
36
+ end
37
+
38
+
39
+ def nav_menu
40
+ input = nil
41
+ until ["exit", "e"].include?(input)
42
+ input = gets.strip.downcase
43
+ if ["menu", "m"].include?(input)
44
+ game_list
45
+ elsif input.to_i >0
46
+ display_game_description(@boardgames[input.to_i-1])
47
+ elsif ["exit", "e"].include?(input)
48
+ puts "", "Goodbye!!"
49
+ else
50
+ puts "You have entered an invalid input"
51
+ end
52
+ end
53
+ end
54
+
55
+ def display_game_description(game)
56
+ puts "", "More information about:", "========================================================="
57
+ puts game.title.upcase
58
+ puts "========================================================="
59
+ puts "Overall Rank: #{game.rank}"
60
+ puts "Average Rating: #{game.avg_rating}"
61
+ puts "Weight (Out of 5): #{game.weight.to_f.round(2)}"
62
+ if game.min_playtime == game.max_playtime
63
+ puts "Estimated Playtime: #{game.min_playtime} mins"
64
+ else
65
+ puts "Estimated Playtime: #{game.min_playtime} - #{game.max_playtime} mins"
66
+ end
67
+ puts "Recommended Age: #{game.min_age}+"
68
+ puts "", "Description:"
69
+ puts game.description, ""
70
+ puts "========================================================="
71
+ puts "", "Enter boardgame number you wish to view", "Enter '[m]enu' to return the main menu", "Enter '[e]xit' to quit program" ,"" ,"Enter your selection:"
72
+ end
73
+ end
@@ -0,0 +1,52 @@
1
+ class TopBoardGames::Game
2
+ attr_accessor :title, :rank, :url, :avg_rating, :game_id
3
+ @@all = []
4
+
5
+ def self.new_from_main_page(game_row)
6
+ title = game_row.css(".collection_objectname a").text
7
+ url = game_row.css(".collection_objectname a").attr("href").text
8
+ avg_rating = game_row.css(".collection_bggrating")[1].text.strip
9
+ game_id = url[/(\/\d*\/)/].gsub("/", "")
10
+ rank = game_row.css(".collection_rank").text.strip
11
+
12
+ self.new(title, rank, url, avg_rating, game_id)
13
+ end
14
+
15
+ def initialize(title = nil, rank = nil, url = nil, avg_rating = nil, game_id=nil)
16
+ @title = title
17
+ @rank = rank
18
+ @url = url
19
+ @avg_rating = avg_rating
20
+ @game_id = game_id
21
+ @@all << self
22
+ end
23
+
24
+ def self.all
25
+ @@all
26
+ end
27
+
28
+ def description
29
+ description_url = Nokogiri::HTML(open("https://boardgamegeek.com#{self.url}")).at("meta[name='description']")['content'].split("\n")
30
+ @description ||= (description_url[0] + " " +description_url[2])
31
+ end
32
+
33
+ def stats_url
34
+ Nokogiri::HTML(open("https://www.boardgamegeek.com/xmlapi2/thing?id=#{self.game_id}&stats=1"))
35
+ end
36
+
37
+ def weight
38
+ @weight ||=stats_url.search("averageweight").first['value']
39
+ end
40
+
41
+ def min_playtime
42
+ @min_playtime ||=stats_url.search("minplaytime").first['value']
43
+ end
44
+
45
+ def max_playtime
46
+ @max_playtime ||=stats_url.search("maxplaytime").first['value']
47
+ end
48
+
49
+ def min_age
50
+ @min_age||=stats_url.search("minage").first['value']
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ class TopBoardGames::Scraper
2
+
3
+ def get_main_page
4
+ #main_page will return the information the info for the list (ie. Rank, Title, etc)
5
+ Nokogiri::HTML(open("https://www.boardgamegeek.com/browse/boardgame"))
6
+ end
7
+
8
+ def scrape_topboardgames
9
+ self.get_main_page.css(".collection_table tr#row_")
10
+ end
11
+
12
+ def make_boardgames
13
+ #this will create new board games and iterate of the main_page
14
+ scrape_topboardgames.each {|row| TopBoardGames::Game.new_from_main_page(row)}
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module TopBoardGames
2
+ VERSION = "0.5.0"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,7 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application => CLI interface allows users to view a list of top games along with allowing them to select a specific one to view more details
5
+ - [X] Pull data from an external source => Data is coming from 3 different pages ("www.boardgamegeek.com) One source is the main page to get basic data, 2nd is to pull 2 "p" of descriptions, lastly 3rd source is from their XML API which was used to get more detailed information
6
+ - [X] Implement both list and detail views => Users can view main list, (total of 20 on screen) or select the game they wish to view more about.
7
+
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TopBoardGames
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - johanesteves
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-21 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: '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
+ description: Returns list of top 100 boardgames from www.boardgamegeek.com, also allows
84
+ to get boardgame description
85
+ email:
86
+ - jsesteves91@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - TopBoardGames-0.1.0.gem
100
+ - TopBoardGames-0.2.0.gem
101
+ - TopBoardGames.gemspec
102
+ - bin/console
103
+ - bin/setup
104
+ - bin/top-boardgames
105
+ - lib/TopBoardGames.rb
106
+ - lib/TopBoardGames/cli.rb
107
+ - lib/TopBoardGames/game.rb
108
+ - lib/TopBoardGames/scraper.rb
109
+ - lib/TopBoardGames/version.rb
110
+ - spec.md
111
+ homepage: https://github.com/johanesteves
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.13
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Returns list of top 100 boardgames from www.boardgamegeek.com
136
+ test_files: []