Class: TopBoardGames::Game
- Inherits:
-
Object
- Object
- TopBoardGames::Game
- Defined in:
- lib/TopBoardGames/game.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#avg_rating ⇒ Object
Returns the value of attribute avg_rating.
-
#game_id ⇒ Object
Returns the value of attribute game_id.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(title = nil, rank = nil, url = nil, avg_rating = nil, game_id = nil) ⇒ Game
constructor
A new instance of Game.
- #max_playtime ⇒ Object
- #min_age ⇒ Object
- #min_playtime ⇒ Object
- #stats_url ⇒ Object
- #weight ⇒ Object
Constructor Details
#initialize(title = nil, rank = nil, url = nil, avg_rating = nil, game_id = nil) ⇒ Game
Returns a new instance of Game.
15 16 17 18 19 20 21 22 |
# File 'lib/TopBoardGames/game.rb', line 15 def initialize(title = nil, rank = nil, url = nil, = nil, game_id=nil) @title = title @rank = rank @url = url @avg_rating = @game_id = game_id @@all << self end |
Instance Attribute Details
#avg_rating ⇒ Object
Returns the value of attribute avg_rating.
2 3 4 |
# File 'lib/TopBoardGames/game.rb', line 2 def @avg_rating end |
#game_id ⇒ Object
Returns the value of attribute game_id.
2 3 4 |
# File 'lib/TopBoardGames/game.rb', line 2 def game_id @game_id end |
#rank ⇒ Object
Returns the value of attribute rank.
2 3 4 |
# File 'lib/TopBoardGames/game.rb', line 2 def rank @rank end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/TopBoardGames/game.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/TopBoardGames/game.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/TopBoardGames/game.rb', line 24 def self.all @@all end |
.new_from_main_page(game_row) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/TopBoardGames/game.rb', line 5 def self.new_from_main_page(game_row) title = game_row.css(".collection_objectname a").text url = game_row.css(".collection_objectname a").attr("href").text = game_row.css(".collection_bggrating")[1].text.strip game_id = url[/(\/\d*\/)/].gsub("/", "") rank = game_row.css(".collection_rank").text.strip self.new(title, rank, url, , game_id) end |
Instance Method Details
#description ⇒ Object
28 29 30 31 |
# File 'lib/TopBoardGames/game.rb', line 28 def description description_url = Nokogiri::HTML(open("https://boardgamegeek.com#{self.url}")).at("meta[name='description']")['content'].split("\n") @description ||= (description_url[0] + " " +description_url[2]) end |
#max_playtime ⇒ Object
45 46 47 |
# File 'lib/TopBoardGames/game.rb', line 45 def max_playtime @max_playtime ||=stats_url.search("maxplaytime").first['value'] end |
#min_age ⇒ Object
49 50 51 |
# File 'lib/TopBoardGames/game.rb', line 49 def min_age @min_age||=stats_url.search("minage").first['value'] end |
#min_playtime ⇒ Object
41 42 43 |
# File 'lib/TopBoardGames/game.rb', line 41 def min_playtime @min_playtime ||=stats_url.search("minplaytime").first['value'] end |
#stats_url ⇒ Object
33 34 35 |
# File 'lib/TopBoardGames/game.rb', line 33 def stats_url Nokogiri::HTML(open("https://www.boardgamegeek.com/xmlapi2/thing?id=#{self.game_id}&stats=1")) end |
#weight ⇒ Object
37 38 39 |
# File 'lib/TopBoardGames/game.rb', line 37 def weight @weight ||=stats_url.search("averageweight").first['value'] end |