class GrooveDl::Displayer

Downloader Class

Attributes

result[R]
type[R]

Public Class Methods

new(result, type) click to toggle source

Initialize Displayer

@param [Array] result The result from the search @param [String] type The search type

@return [Nil]

# File lib/groove-dl/displayer.rb, line 14
def initialize(result, type)
  @result = result
  @type = type
end

Public Instance Methods

add_row(table, data) click to toggle source

Add row into table

@param [Terminal::Table] table Table in which row will be added @param [Array] result The result from the search

@return [Nil]

# File lib/groove-dl/displayer.rb, line 44
def add_row(table, data)
  table.add_row([data.id,
                 data.name,
                 data.username,
                 data.num_songs]) if @type == 'Playlists'
  table.add_row([data.id,
                 data.album,
                 data.artist,
                 data.name]) if @type == 'Songs'
end
headers() click to toggle source
# File lib/groove-dl/displayer.rb, line 31
def headers
  return %w(Id Album Artist Song) if @type == 'Songs'
  return %w(Id Name Author NumSongs) if @type == 'Playlists'
end
render() click to toggle source

Display prompt to choose songs or playlists.

# File lib/groove-dl/displayer.rb, line 22
def render
  table = Terminal::Table.new(headings: headers, title: @type)
  @result.each do |data|
    add_row(table, data)
  end

  puts table.to_s
end