Top Level Namespace

Defined Under Namespace

Modules: Ampt

Instance Method Summary collapse

Instance Method Details

#bggreen(text) ⇒ Object



15
# File 'lib/ampt_cfg/default.rb', line 15

def bggreen(text); color(text, "\e[42m"); end

#bold(text) ⇒ Object



13
# File 'lib/ampt_cfg/default.rb', line 13

def bold(text); color(text, "\e[1m"); end

#color(text, color_code) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/ampt_cfg/default.rb', line 3

def color(text, color_code)
  if @color
      "#{color_code}#{text}\e[0m"
  else
      text
  end
end

#green(text) ⇒ Object



12
# File 'lib/ampt_cfg/default.rb', line 12

def green(text); color(text, "\e[32m"); end

#pp_song(song, options = {:title => true, :artist => true, :album => false, :track => false}) ⇒ Object



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
# File 'lib/ampt_cfg/default.rb', line 17

def pp_song song, options={:title => true, :artist => true, :album => false, :track => false}
    song_id = song.song_id
    if song_id.nil?
        puts "  Nothing."
        raise "Not playing."
    end
    artist  = song.artist
    path    = song.path
    title   = song.title
    title   = path.split('/')[-1].rpartition('.')[0] if title.empty?
    track   = song.track
    album   = song.album
    who     = if song.respond_to? :who
                song.who
              else
                []
              end
    str = ["[#{green(song_id.rjust(7))}]"]
    if options[:track]
        str <<= "#{track.rjust(3)}."
    end
    if options[:title]
        str <<= "#{under(title[0...40].strip)}"
    end
    if options[:artist] and not artist.empty?
        str <<= "by #{(artist[0..20].strip)}"
    end
    if options[:album] and not album.empty?
        str <<= "on #{(album[0..20].strip)}"
    end
    unless who.empty?
        str <<= "\nVoted up by"
        if who.size > 1 and (not options[:show_all_voters])
            str <<= "#{who[0]} (and #{who.length - 1} other#{'s' if who.length > 2})"
        elsif who.size > 1 and options[:show_all_voters]
            str <<= who.join(', ')
        else
            str <<= who[0]
        end
    end
    str.join(' ')
end

#pp_songs(songs) ⇒ Object



60
61
62
63
64
# File 'lib/ampt_cfg/default.rb', line 60

def pp_songs songs
    songs.each do |song|
        pp_song(song).lines.each {|l| puts "  " + l}
    end
end

#pp_songs_full(songs, options = {}) ⇒ Object



77
78
79
80
81
82
# File 'lib/ampt_cfg/default.rb', line 77

def pp_songs_full songs, options = {}
    opts = {:title => true, :artist => true, :album => true, :track => true}.merge(options)
    songs.each do |song|
        pp_song(song, opts).lines.each {|l| puts "  " + l}
    end
end

#pp_time(len) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/ampt_cfg/default.rb', line 84

def pp_time len
    len = len.to_i
    str = if len > 3600
              format("%d:%02d", len/3600, (len/60)%60)
          else
              (len / 60).to_s
          end
    str << format(":%02d", len % 60)
end

#red(text) ⇒ Object



11
# File 'lib/ampt_cfg/default.rb', line 11

def red(text); color(text, "\e[31m"); end

#select_interactively(l) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ampt_cfg/default.rb', line 94

def select_interactively l
    s = []
    Tempfile.open("ampt") do |tempfile|
        songs_to_file(l, tempfile)
        tempfile.fsync
        tempfile.flush
        path = tempfile.path
        tempfile.close
        system(ENV['EDITOR'], path)
        File.open(path) do |f|
            s = f.readlines
        end
    end
    s.inject([]) do |a,line|
        a + ((line.scan(/\s(\d+)\s/)[0] unless(line =~ /^\#/)) || [])
    end
end

#songs_to_file(songs, file) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/ampt_cfg/default.rb', line 66

def songs_to_file songs, file
    songs.uniq!
    s = [sprintf("#\t%7s %3s   %20s   %20s   %20s", 'song_id', '#', 'title', 'artist',
        'album')]
    s += songs.collect do |song|
        sprintf("#\t%7s %3s   %20.20s   %20.20s   %20.20s", song.song_id, song.track,
                song.title, song.artist, song.album)
    end
    file.write(s.join("\n"))
end

#under(text) ⇒ Object



14
# File 'lib/ampt_cfg/default.rb', line 14

def under(text); color(text, "\e[4m"); end