Class: Album

Inherits:
Object
  • Object
show all
Defined in:
lib/discogs/wishlist/models/album.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Album

Returns a new instance of Album.



4
5
6
# File 'lib/discogs/wishlist/models/album.rb', line 4

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/discogs/wishlist/models/album.rb', line 2

def id
  @id
end

Instance Method Details

#add_variation(variation) ⇒ Object



8
9
10
# File 'lib/discogs/wishlist/models/album.rb', line 8

def add_variation(variation)
  variations << variation
end

#artistObject



16
17
18
# File 'lib/discogs/wishlist/models/album.rb', line 16

def artist
  @artist ||= variations.first&.artist
end

#items_for_sale_countObject



40
41
42
# File 'lib/discogs/wishlist/models/album.rb', line 40

def items_for_sale_count
  @items_for_sale_count ||= saleable_variations.sum(&:items_for_sale_count)
end

#lowest_priceObject



20
21
22
23
24
25
26
# File 'lib/discogs/wishlist/models/album.rb', line 20

def lowest_price
  @lowest_price ||= begin
    return nil unless items_for_sale_count.positive?

    saleable_variations.map(&:lowest_price).min_by { |price| price[:price] }
  end
end

#lowest_price_costObject



28
29
30
31
32
# File 'lib/discogs/wishlist/models/album.rb', line 28

def lowest_price_cost
  return nil if lowest_price.nil?

  @lowest_price_cost ||= lowest_price[:price].format
end

#lowest_price_shippingObject



34
35
36
37
38
# File 'lib/discogs/wishlist/models/album.rb', line 34

def lowest_price_shipping
  return nil if lowest_price.nil?

  @lowest_price_shipping ||= lowest_price[:shipping].format
end

#saleable_variationsObject



44
45
46
# File 'lib/discogs/wishlist/models/album.rb', line 44

def saleable_variations
  @saleable_variations ||= variations.select(&:saleable?)
end

#titleObject



12
13
14
# File 'lib/discogs/wishlist/models/album.rb', line 12

def title
  @title ||= variations.first&.title
end

#variationsObject



48
49
50
# File 'lib/discogs/wishlist/models/album.rb', line 48

def variations
  @variations ||= []
end