class WishlistPrinter

Attributes

show_for_sale[R]
wishlist[R]

Public Class Methods

new(wishlist:, show_for_sale:) click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 4
def initialize(wishlist:, show_for_sale:)
  @wishlist = wishlist
  @show_for_sale = show_for_sale
end

Public Instance Methods

print!() click to toggle source

Private Instance Methods

album_columns(album) click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 33
def album_columns(album)
  columns = [
    album.title,
    album.artist,
    album.variations.length
  ]

  return columns unless show_for_sale

  columns + [
    album.items_for_sale_count,
    album.lowest_price_cost,
    album.lowest_price_shipping
  ]
end
headings() click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 49
def headings
  common_headings = ["Title", "Artist", "Variations"]

  return common_headings unless show_for_sale

  country_code = wishlist.country ? "(#{wishlist.country.alpha2})" : ""

  common_headings + [
    "For Sale #{country_code}",
    "Lowest Price #{country_code}",
    "Shipping #{country_code}"
  ]
end
populate_table() click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 19
def populate_table
  wishlist.each do |album|
    table.add_row(album_columns(album))
  end
end
table() click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 25
def table
  @table ||= Terminal::Table.new(title: title, headings: headings)
end
title() click to toggle source
# File lib/discogs/wishlist/printers/wishlist_printer.rb, line 29
def title
  "Wishlist"
end