Class: GrooveDl::Displayer

Inherits:
Object
  • Object
show all
Defined in:
lib/groove-dl/displayer.rb

Overview

Downloader Class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, type) ⇒ Nil

Initialize Displayer



15
16
17
18
# File 'lib/groove-dl/displayer.rb', line 15

def initialize(result, type)
  @result = result
  @type = type
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/groove-dl/displayer.rb', line 5

def result
  @result
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/groove-dl/displayer.rb', line 5

def type
  @type
end

Instance Method Details

#add_row(table, data) ⇒ Nil

Add row into table



45
46
47
48
49
50
51
52
53
54
# File 'lib/groove-dl/displayer.rb', line 45

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

#headersObject



32
33
34
35
# File 'lib/groove-dl/displayer.rb', line 32

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

#renderObject

Display prompt to choose songs or playlists.



23
24
25
26
27
28
29
30
# File 'lib/groove-dl/displayer.rb', line 23

def render
  table = Terminal::Table.new(headings: headers, title: @type)
  @result.each do |data|
    add_row(table, data)
  end

  puts table.to_s
end