Class: Album
- Inherits:
-
Object
- Object
- Album
- Defined in:
- lib/discogs/wishlist/models/album.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add_variation(variation) ⇒ Object
- #artist ⇒ Object
-
#initialize(id) ⇒ Album
constructor
A new instance of Album.
- #items_for_sale_count ⇒ Object
- #lowest_price ⇒ Object
- #lowest_price_cost ⇒ Object
- #lowest_price_shipping ⇒ Object
- #saleable_variations ⇒ Object
- #title ⇒ Object
- #variations ⇒ Object
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
#id ⇒ Object (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 |
#artist ⇒ Object
16 17 18 |
# File 'lib/discogs/wishlist/models/album.rb', line 16 def artist @artist ||= variations.first&.artist end |
#items_for_sale_count ⇒ Object
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_price ⇒ Object
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_cost ⇒ Object
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_shipping ⇒ Object
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_variations ⇒ Object
44 45 46 |
# File 'lib/discogs/wishlist/models/album.rb', line 44 def saleable_variations @saleable_variations ||= variations.select(&:saleable?) end |
#title ⇒ Object
12 13 14 |
# File 'lib/discogs/wishlist/models/album.rb', line 12 def title @title ||= variations.first&.title end |
#variations ⇒ Object
48 49 50 |
# File 'lib/discogs/wishlist/models/album.rb', line 48 def variations @variations ||= [] end |