Module: Meuh::Formatting
- Defined in:
- lib/meuh/formatting.rb
Class Method Summary collapse
-
.text(tracks, color = true) ⇒ Object
Format tracks for text output (e.g. in the terminal).
Instance Method Summary collapse
-
#track_text(t, style, color) ⇒ Object
:previous, :next, :curr.
Class Method Details
.text(tracks, color = true) ⇒ Object
Format tracks for text output (e.g. in the terminal)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/meuh/formatting.rb', line 8 def text(tracks, color=true) if color require 'colored' # this line is from github.com/defunkt/colored require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/ end s = [] def track_text(t, style, color) # :previous, :next, :curr title = t[:title] || '' artist = t[:artist] album = t[:album] time = style == :previous ? "[#{t[:time]}] " : '' title.strip! if color title = title.underline if artist and style == :curr artist = artist.cyan end end info = [artist, album].compact info = info.empty? ? '' : " (#{info.map(&:to_s).join(' - ')})" if style == :curr and color info = info.green end ts = "#{time}#{title}#{info}" ts = "* #{ts}" unless style == :curr ts end if tracks[:current] s << track_text(tracks[:current], :curr, color) end if tracks[:previous] and !tracks[:previous].empty? s << "\nPreviously:" tracks[:previous].each do |t| s << track_text(t, :previous, color) end end if tracks[:next] and !tracks[:next].empty? s << "\nNext:" tracks[:next].each do |t| s << track_text(t, :next, color) end end s.join("\n") end |
Instance Method Details
#track_text(t, style, color) ⇒ Object
:previous, :next, :curr
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meuh/formatting.rb', line 16 def track_text(t, style, color) # :previous, :next, :curr title = t[:title] || '' artist = t[:artist] album = t[:album] time = style == :previous ? "[#{t[:time]}] " : '' title.strip! if color title = title.underline if artist and style == :curr artist = artist.cyan end end info = [artist, album].compact info = info.empty? ? '' : " (#{info.map(&:to_s).join(' - ')})" if style == :curr and color info = info.green end ts = "#{time}#{title}#{info}" ts = "* #{ts}" unless style == :curr ts end |