class Bgg::Collection
Public Class Methods
find_by_username(username)
click to toggle source
# File lib/bgg/collection.rb, line 3 def self.find_by_username(username) if username =~ /^\d*$/ # this is a sorta hokey restriction because there is probably nothing requiring # users to have non-numeric usernames. I'm not sure that I've seen one though. raise ArgumentError.new('username must not be empty or only digits!') end if username.is_a?(Integer) raise ArgumentError.new('username must not be an Integer!') end collection_data = BggApi.collection({username: username}) unless collection_data.has_key?('item') raise ArgumentError.new('User does not exist') end Bgg::Collection.new(collection_data) end
new(collection_data)
click to toggle source
# File lib/bgg/collection.rb, line 25 def initialize(collection_data) @items = [] collection_data['item'].each do |item| bgg_item = Bgg::Collection::Item.new(item) @items.push(bgg_item) end end
Public Instance Methods
boardgame_expansions()
click to toggle source
# File lib/bgg/collection.rb, line 50 def boardgame_expansions @items.select{ |item| item.name =~ /expansion/i } end
boardgames()
click to toggle source
# File lib/bgg/collection.rb, line 46 def boardgames @items.select{ |item| item.type == 'boardgame' } end
count()
click to toggle source
# File lib/bgg/collection.rb, line 38 def count self.size end
owned()
click to toggle source
# File lib/bgg/collection.rb, line 42 def owned @items.select{ |item| item.owned? } end
played()
click to toggle source
# File lib/bgg/collection.rb, line 54 def played @items.select{ |item| item.played? } end
size()
click to toggle source
# File lib/bgg/collection.rb, line 34 def size @items.size end