Class: Cinch::Plugins::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, user_xml, collection_xml) ⇒ User

Returns a new instance of User.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/cinch/plugins/bgg.rb', line 254

def initialize(username, user_xml, collection_xml)
  self.name       = username
  self.top_games  = user_xml.css("top item").map{ |g| g["name"] }
  self.hot_games  = user_xml.css("hot item").map{ |g| g["name"] }
  self.collection = {}
  collection_xml.css("items item").each do |g| 
    self.collection[g["objectid"]]              = {}
    self.collection[g["objectid"]]["name"]      = g.css("name")[0].content
    self.collection[g["objectid"]]["own"]       = g.css("status")[0]['own'].to_i
    self.collection[g["objectid"]]["for_trade"] = g.css("status")[0]['fortrade'].to_i
    self.collection[g["objectid"]]["want"]      = g.css("status")[0]['want'].to_i
    self.collection[g["objectid"]]["plays"]     = g.css("numplays")[0].content.to_i
    self.collection[g["objectid"]]["rating"]    = g.css("stats")[0].css("rating")[0]['value']
  end
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



252
253
254
# File 'lib/cinch/plugins/bgg.rb', line 252

def collection
  @collection
end

#hot_gamesObject

Returns the value of attribute hot_games.



252
253
254
# File 'lib/cinch/plugins/bgg.rb', line 252

def hot_games
  @hot_games
end

#nameObject

Returns the value of attribute name.



252
253
254
# File 'lib/cinch/plugins/bgg.rb', line 252

def name
  @name
end

#top_gamesObject

Returns the value of attribute top_games.



252
253
254
# File 'lib/cinch/plugins/bgg.rb', line 252

def top_games
  @top_games
end

Instance Method Details

#ownedObject



270
271
272
# File 'lib/cinch/plugins/bgg.rb', line 270

def owned
  self.collection.select{ |id, game| game["own"] == 1 }
end

#playedObject



286
287
288
# File 'lib/cinch/plugins/bgg.rb', line 286

def played
  self.collection.select{ |id, game| game["plays"] > 0 }
end

#ratedObject



282
283
284
# File 'lib/cinch/plugins/bgg.rb', line 282

def rated
  self.collection.reject{ |id, game| game["rating"] == "N/A" }
end

#tradingObject



274
275
276
# File 'lib/cinch/plugins/bgg.rb', line 274

def trading
  self.collection.select{ |id, game| game["for_trade"] == 1 }
end

#wantedObject



278
279
280
# File 'lib/cinch/plugins/bgg.rb', line 278

def wanted
  self.collection.select{ |id, game| game["want"] == 1 }
end