Class: Bgg::Collection
- Inherits:
-
Object
- Object
- Bgg::Collection
- Defined in:
- lib/bgg/collection.rb,
lib/bgg/collection.rb,
lib/bgg/collection_item.rb
Defined Under Namespace
Classes: Item
Class Method Summary collapse
Instance Method Summary collapse
- #boardgame_expansions ⇒ Object
- #boardgames ⇒ Object
- #count ⇒ Object
-
#initialize(collection_data) ⇒ Collection
constructor
A new instance of Collection.
- #owned ⇒ Object
- #played ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(collection_data) ⇒ Collection
Returns a new instance of Collection.
25 26 27 28 29 30 31 32 |
# 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 |
Class Method Details
.find_by_username(username) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Method Details
#boardgame_expansions ⇒ Object
50 51 52 |
# File 'lib/bgg/collection.rb', line 50 def boardgame_expansions @items.select{ |item| item.name =~ /expansion/i } end |
#boardgames ⇒ Object
46 47 48 |
# File 'lib/bgg/collection.rb', line 46 def boardgames @items.select{ |item| item.type == 'boardgame' } end |
#count ⇒ Object
38 39 40 |
# File 'lib/bgg/collection.rb', line 38 def count self.size end |
#owned ⇒ Object
42 43 44 |
# File 'lib/bgg/collection.rb', line 42 def owned @items.select{ |item| item.owned? } end |
#played ⇒ Object
54 55 56 |
# File 'lib/bgg/collection.rb', line 54 def played @items.select{ |item| item.played? } end |
#size ⇒ Object
34 35 36 |
# File 'lib/bgg/collection.rb', line 34 def size @items.size end |