Sha256: 182e99dabe5dd364866695ab200163bc59e18cd7754a8293e42ba69c8c04baa3

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# -*- coding: utf-8 -*-
module GrooveDl
  # Downloader Class
  class Displayer
    attr_reader :result, :type

    ##
    # Initialize Displayer
    #
    # @params [Array] result The result from the search
    # @params [String] type The search type
    #
    # @return [Nil]
    #
    def initialize(result, type)
      @result = result
      @type = type
    end

    ##
    # Display prompt to choose songs or playlists.
    #
    def render
      table = Terminal::Table.new(headings: headers, title: @type)
      @result.each do |data|
        add_row(table, data)
      end

      puts table.to_s
    end

    def headers
      return %w(Id Album Artist Song) if @type == 'Songs'
      return %w(Id Nam Author NumSongs) if @type == 'Playlists'
    end

    ##
    # Add row into table
    #
    # @params [Terminal::Table] table Table in which row will be added
    # @params [Array] result The result from the search
    #
    # @return [Nil]
    #
    def add_row(table, data)
      table.add_row([data['playlist_id'],
                     data['name'],
                     data['f_name'],
                     data['num_songs']]) if @type == 'Playlists'
      table.add_row([data.id,
                     data.album,
                     data.artist,
                     data.name]) if @type == 'Songs'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
groove-dl-0.2.0 lib/groove-dl/displayer.rb
groove-dl-0.1.0 lib/groove-dl/displayer.rb