Class: Bgg::Collection::Item

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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

#commentObject (readonly)

Returns the value of attribute comment.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def comment
  @comment
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def id
  @id
end

#imageObject (readonly)

Returns the value of attribute image.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def image
  @image
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def name
  @name
end

#play_countObject (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

#thumbnailObject (readonly)

Returns the value of attribute thumbnail.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def thumbnail
  @thumbnail
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/bgg/collection_item.rb', line 4

def type
  @type
end

#year_publishedObject (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

Returns:

  • (Boolean)


39
40
41
# File 'lib/bgg/collection_item.rb', line 39

def for_trade?
  @for_trade
end

#gameObject



63
64
65
# File 'lib/bgg/collection_item.rb', line 63

def game
  Bgg::Game.find_by_id(self.id)
end

#owned?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/bgg/collection_item.rb', line 43

def owned?
  @owned
end

#played?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/bgg/collection_item.rb', line 31

def played?
  @play_count > 0
end

#preordered?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/bgg/collection_item.rb', line 55

def preordered?
  @preordered
end

#published?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bgg/collection_item.rb', line 59

def published?
  @year_published != 0
end

#want_to_buy?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bgg/collection_item.rb', line 51

def want_to_buy?
  @want_to_buy
end

#want_to_play?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/bgg/collection_item.rb', line 47

def want_to_play?
  @want_to_play
end

#wanted?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/bgg/collection_item.rb', line 35

def wanted?
  @wanted
end