Class: Cinch::Plugins::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugins/bgg.rb

Constant Summary collapse

NOT_RANKED_RANK =
10001

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, xml) ⇒ Game

Returns a new instance of Game.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/cinch/plugins/bgg.rb', line 226

def initialize(id, xml)        
  self.id          = id
  self.rating      = xml.css('statistics ratings average')[0]['value'].to_f
  self.rank        = xml.css('statistics ratings ranks rank')[0]["value"]
  # if ranked, convert the value to integer; if not, set the value of the rank to the last possible
  self.rank        = self.rank == "Not Ranked" ? NOT_RANKED_RANK : self.rank.to_i
  self.name        = xml.css('name')[0]['value']
  self.year        = xml.css('yearpublished')[0]['value'].to_i
  self.minplayers  = xml.css('minplayers')[0]['value'].to_i
  self.maxplayers  = xml.css('maxplayers')[0]['value'].to_i
  self.playingtime = xml.css('playingtime')[0]['value'].to_i
  self.categories  = xml.css('link[type=boardgamecategory]').map{ |l| l['value'] }
  self.mechanics   = xml.css('link[type=boardgamemechanic]').map{ |l| l['value'] }
  self.designers   = xml.css('link[type=boardgamedesigner]').map{ |l| l['value'] }
  self.publishers  = xml.css('link[type=boardgamepublisher]').map{ |l| l['value'] }
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def categories
  @categories
end

#designersObject

Returns the value of attribute designers.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def designers
  @designers
end

#idObject

Returns the value of attribute id.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def id
  @id
end

#maxplayersObject

Returns the value of attribute maxplayers.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def maxplayers
  @maxplayers
end

#mechanicsObject

Returns the value of attribute mechanics.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def mechanics
  @mechanics
end

#minplayersObject

Returns the value of attribute minplayers.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def minplayers
  @minplayers
end

#nameObject

Returns the value of attribute name.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def name
  @name
end

#playingtimeObject

Returns the value of attribute playingtime.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def playingtime
  @playingtime
end

#publishersObject

Returns the value of attribute publishers.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def publishers
  @publishers
end

#rankObject

Returns the value of attribute rank.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def rank
  @rank
end

#ratingObject

Returns the value of attribute rating.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def rating
  @rating
end

#yearObject

Returns the value of attribute year.



222
223
224
# File 'lib/cinch/plugins/bgg.rb', line 222

def year
  @year
end

Instance Method Details

#game_rankObject

Since we are resetting the not ranked values, let’s make sure we return the correct values



245
246
247
# File 'lib/cinch/plugins/bgg.rb', line 245

def game_rank
  (self.rank == NOT_RANKED_RANK) ? "Not Ranked" : self.rank  
end