Class: Pandata::DataFormatter
- Inherits:
-
Object
- Object
- Pandata::DataFormatter
- Defined in:
- lib/pandata/data_formatter.rb
Overview
Sorts and formats Pandata::Scraper data as a string for printing.
Instance Method Summary collapse
-
#albums(albums) ⇒ Object
Returns a string with albums grouped under owning artist.
-
#followx(data) ⇒ Object
Returns a string with followers/ing sorted by webname.
-
#list(data) ⇒ Object
Returns a string with each array item on its own line.
-
#sort_list(data) ⇒ Object
Identical to #list but sorts alphabetically ignoring ‘the’.
-
#tracks(tracks) ⇒ Object
Returns a string with tracks grouped under owning artist.
Instance Method Details
#albums(albums) ⇒ Object
Returns a string with albums grouped under owning artist.
31 32 33 |
# File 'lib/pandata/data_formatter.rb', line 31 def albums(albums) artists_items(albums, :album) end |
#followx(data) ⇒ Object
Returns a string with followers/ing sorted by webname.
37 38 39 40 41 42 43 44 45 |
# File 'lib/pandata/data_formatter.rb', line 37 def followx(data) str = '' data.sort_by { |item| item[:webname].downcase }.each do |hash| str << " - name: #{hash[:name]}\n" str << " webname: #{hash[:webname]}\n" str << " href: #{hash[:href]}\n" end str end |
#list(data) ⇒ Object
Returns a string with each array item on its own line.
10 11 12 13 14 15 |
# File 'lib/pandata/data_formatter.rb', line 10 def list(data) data = [data] unless data.kind_of?(Array) str = '' data.each { |item| str << " - #{item}\n" } str end |
#sort_list(data) ⇒ Object
Identical to #list but sorts alphabetically ignoring ‘the’.
19 20 21 |
# File 'lib/pandata/data_formatter.rb', line 19 def sort_list(data) list custom_sort(data) end |
#tracks(tracks) ⇒ Object
Returns a string with tracks grouped under owning artist.
25 26 27 |
# File 'lib/pandata/data_formatter.rb', line 25 def tracks(tracks) artists_items(tracks, :track) end |