Class: GrooveDl::Displayer
- Inherits:
-
Object
- Object
- GrooveDl::Displayer
- Defined in:
- lib/groove-dl/displayer.rb
Overview
Downloader Class
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#add_row(table, data) ⇒ Nil
Add row into table.
- #headers ⇒ Object
-
#initialize(result, type) ⇒ Nil
constructor
Initialize Displayer.
-
#render ⇒ Object
Display prompt to choose songs or playlists.
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
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/groove-dl/displayer.rb', line 5 def result @result end |
#type ⇒ Object (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 |
#headers ⇒ Object
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 |
#render ⇒ Object
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 |