Class: Bgg::Collection::Item
- Inherits:
-
Object
- Object
- Bgg::Collection::Item
- Defined in:
- lib/bgg/collection_item.rb
Instance Attribute Summary collapse
-
#collection_id ⇒ Object
readonly
Returns the value of attribute collection_id.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#play_count ⇒ Object
readonly
Returns the value of attribute play_count.
-
#thumbnail ⇒ Object
readonly
Returns the value of attribute thumbnail.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#year_published ⇒ Object
readonly
Returns the value of attribute year_published.
Instance Method Summary collapse
- #for_trade? ⇒ Boolean
- #game ⇒ Object
-
#initialize(item) ⇒ Item
constructor
A new instance of Item.
- #owned? ⇒ Boolean
- #played? ⇒ Boolean
- #preordered? ⇒ Boolean
- #published? ⇒ Boolean
- #want_to_buy? ⇒ Boolean
- #want_to_play? ⇒ Boolean
- #wanted? ⇒ Boolean
Constructor Details
#initialize(item) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bgg/collection_item.rb', line 7 def initialize(item) # Integers @id = item['objectid'].to_i @collection_id = item['collid'].to_i @play_count = item['numplays'][0].to_i @comment = item.fetch('comment', [])[0] @image = item['image'][0] @name = item['name'][0]['content'] @thumbnail = item['thumbnail'][0] @type = item['subtype'] # booleans @owned = item['status'][0]['own'] == '1' @for_trade = item['status'][0]['fortrade'] == '1' @preordered = item['status'][0]['preordered'] == '1' @want_to_buy = item['status'][0]['wanttobuy'] == '1' @want_to_play = item['status'][0]['wanttoplay'] == '1' @wanted = item['status'][0]['want'] == '1' # special handling @year_published = item.fetch('yearpublished', ['0'])[0].to_i end |
Instance Attribute Details
#collection_id ⇒ Object (readonly)
Returns the value of attribute collection_id.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def collection_id @collection_id end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def comment @comment end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def image @image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def name @name end |
#play_count ⇒ Object (readonly)
Returns the value of attribute play_count.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def play_count @play_count end |
#thumbnail ⇒ Object (readonly)
Returns the value of attribute thumbnail.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def thumbnail @thumbnail end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def type @type end |
#year_published ⇒ Object (readonly)
Returns the value of attribute year_published.
4 5 6 |
# File 'lib/bgg/collection_item.rb', line 4 def year_published @year_published end |
Instance Method Details
#for_trade? ⇒ Boolean
39 40 41 |
# File 'lib/bgg/collection_item.rb', line 39 def for_trade? @for_trade end |
#game ⇒ Object
63 64 65 |
# File 'lib/bgg/collection_item.rb', line 63 def game Bgg::Game.find_by_id(self.id) end |
#owned? ⇒ Boolean
43 44 45 |
# File 'lib/bgg/collection_item.rb', line 43 def owned? @owned end |
#played? ⇒ Boolean
31 32 33 |
# File 'lib/bgg/collection_item.rb', line 31 def played? @play_count > 0 end |
#preordered? ⇒ Boolean
55 56 57 |
# File 'lib/bgg/collection_item.rb', line 55 def preordered? @preordered end |
#published? ⇒ Boolean
59 60 61 |
# File 'lib/bgg/collection_item.rb', line 59 def published? @year_published != 0 end |
#want_to_buy? ⇒ Boolean
51 52 53 |
# File 'lib/bgg/collection_item.rb', line 51 def want_to_buy? @want_to_buy end |
#want_to_play? ⇒ Boolean
47 48 49 |
# File 'lib/bgg/collection_item.rb', line 47 def want_to_play? @want_to_play end |
#wanted? ⇒ Boolean
35 36 37 |
# File 'lib/bgg/collection_item.rb', line 35 def wanted? @wanted end |