Module: AlbumCredits::Display
- Included in:
- Finder
- Defined in:
- lib/album_credits/display.rb
Constant Summary collapse
- COLORS =
{ :clear => "\e[0m", :bold => "\e[1m", :black => "\e[30m", :white => "\e[37m", :red => "\e[31m", :green => "\e[32m", :yellow => "\e[33m", :blue => "\e[34m" }
Instance Method Summary collapse
-
#cp(text, opts = {}) ⇒ Object
Prints the text in color.
- #default_color ⇒ Object
-
#display_engineer_data(engineers, opts = {}) ⇒ Object
IDEA: show a cross-section of their work.
- #display_release(release, engineers, opts = {}) ⇒ Object
- #engineer_discog_max ⇒ Object
- #get_artist_discog(artist) ⇒ Object
- #image_uri_for_release(release) ⇒ Object
Instance Method Details
#cp(text, opts = {}) ⇒ Object
Prints the text in color
31 32 33 34 35 |
# File 'lib/album_credits/display.rb', line 31 def cp(text, opts={}) embolden = opts[:bold] ? COLORS[:bold] : '' color = opts[:color] || default_color puts "#{embolden}#{COLORS[color]}#{text}#{COLORS[:clear]}" end |
#default_color ⇒ Object
17 18 19 |
# File 'lib/album_credits/display.rb', line 17 def default_color :white end |
#display_engineer_data(engineers, opts = {}) ⇒ Object
IDEA: show a cross-section of their work. maybe start with around the year that current album was released if there are many. ALSO: could filter their discog. output by x-ref w/ the role they played on this album. e.g. only show Bob Ludwig’s mastering work, not mixing.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/album_credits/display.rb', line 66 def display_engineer_data(engineers, opts={}) show_discography = opts[:show_discography] == true displayed = [] cp "Engineers:", :color => :yellow engineers.each do |engineer| next if displayed.include? engineer.name cp "#{engineer.name}: #{engineer.role}", :bold => true, :color => :red engineer_details = discogs.get_artist(engineer.id) if (!engineer_details.nil?) aka = engineer_details.namevariations || [] aka << engineer_details.aliases.map(&:name) unless engineer_details.aliases.nil? if !(aliases = aka.flatten.uniq.sort).empty? cp "AKA: #{aliases.first(10).join(', ')}" end end # Print the engineer's discography engineer_discog = get_artist_discog(engineer_details) if show_discography && !engineer_discog.nil? && engineer.role.match(/assisted|assistant|additional/i).nil? discog_cnt = engineer_discog.releases.size == engineer_discog_max ? "#{engineer_discog_max}+" : engineer_discog.releases.size cp "#{discog_cnt} releases in discography", :color => :yellow cp engineer_details.uri engineer_discog.releases.group_by{ |disk| disk.year }.sort_by{ |year, _| year || 0 }.reverse.each do |year, albums| cp year, :bold => true, :color => :blue albums.each do |a| cp " * #{a.artist} - \"#{a.title}\", [#{a.role}]" end end displayed << engineer_details.name end puts end end |
#display_release(release, engineers, opts = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/album_credits/display.rb', line 44 def display_release(release, engineers, opts={}) cp "="*40 cp release.title cp "#{release.tracklist.size} songs, released: #{release.released}" cp release.uri cp release.notes cp "" display_engineer_data(engineers, opts) end |
#engineer_discog_max ⇒ Object
21 22 23 |
# File 'lib/album_credits/display.rb', line 21 def engineer_discog_max 100 end |
#get_artist_discog(artist) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/album_credits/display.rb', line 54 def get_artist_discog(artist) begin discogs.get_artists_releases(artist.id, per_page: engineer_discog_max, page: 1) rescue Exception => e puts e end end |
#image_uri_for_release(release) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/album_credits/display.rb', line 37 def image_uri_for_release(release) return if release.images.nil? img = release.images.detect{|i| i.type == 'primary'} img = release.images.detect{|i| i.type == 'secondary'} if img.nil? img.uri if img end |