Class: Qtunes::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/qtunes/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.libraryObject



96
97
98
99
100
101
102
103
# File 'lib/qtunes/server.rb', line 96

def self.library
  @library ||= begin
    print "Loading library..."
    result = songs_to_hash{ player.library }
    puts "Done"
    result
  end
end

.library_by_first_letter_of_artistObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/qtunes/server.rb', line 81

def self.library_by_first_letter_of_artist
  @library_by_first_letter_of_artist ||= begin
    result = Hash.new{|h,k| h[k] = Array.new }
    library.values.inject(result) do |res,song| 
      key = song['artist'] ? string_to_ascii(song['artist']).downcase[0,1] : ''
      res[key] << song
      res
    end
  end
end

.playerObject



65
66
67
# File 'lib/qtunes/server.rb', line 65

def self.player
  @player ||= Qtunes::Player.new
end

.queueObject



73
74
75
# File 'lib/qtunes/server.rb', line 73

def self.queue
  songs_to_hash{ player.queue }
end

.string_to_ascii(s) ⇒ Object



109
110
111
112
# File 'lib/qtunes/server.rb', line 109

def self.string_to_ascii(s)
  require 'unicode'
  Unicode::normalize_KD(s).gsub(/[^A-Za-z0-9\s_-]+/,'')
end

Instance Method Details

#libraryObject



105
106
107
# File 'lib/qtunes/server.rb', line 105

def library
  self.class.library
end

#library_by_first_letter_of_artistObject



92
93
94
# File 'lib/qtunes/server.rb', line 92

def library_by_first_letter_of_artist
  self.class.library_by_first_letter_of_artist
end

#playerObject



69
70
71
# File 'lib/qtunes/server.rb', line 69

def player
  self.class.player
end

#queueObject



77
78
79
# File 'lib/qtunes/server.rb', line 77

def queue
  self.class.queue
end

#string_to_ascii(s) ⇒ Object



114
115
116
# File 'lib/qtunes/server.rb', line 114

def string_to_ascii(s)
  self.class.string_to_ascii(s)
end