Class: Site

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/terminal_player/site.rb

Direct Known Subclasses

DI, Soma, Spotiphy

Defined Under Namespace

Classes: Observer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, name) ⇒ Site

Returns a new instance of Site.



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
# File 'lib/terminal_player/site.rb', line 9

def initialize(options, name)
  @name = name
  @songs = []
  @channels = []

  options[:cache] || options[:cache] = 512
  options[:cache_min] || options[:cache_min] = 30
  options[:url] || options[:url] = ''

  if options[:url].nil? || options[:url].empty?
    fail "no :url in the options hash sent to Site"
  end

  @is_di_plus = options[:di_plus]

  @is_spotify = !options[:url]['spotify:'].nil?
  if @is_spotify
    @current_channel = spotify_type(options[:url])
  else
    @current_channel = options[:url].split('/').last
    @current_channel = @current_channel[0..@current_channel.index('.') - 1]
  end

  if @is_spotify
    @is_mplayer = false
    @player = SpotiphyPlayer.new(options)
  else
    @is_mplayer = true
    @player = Mplayer.new({cache: options[:cache],
                           cache_min: options[:cache_min],
                           url: options[:url]})
  end
  PlayerMessageObserver.new(self, @player)
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def channels
  @channels
end

#current_channelObject (readonly)

Returns the value of attribute current_channel.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def current_channel
  @current_channel
end

#is_di_plusObject (readonly)

Returns the value of attribute is_di_plus.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def is_di_plus
  @is_di_plus
end

#is_mplayerObject (readonly)

Returns the value of attribute is_mplayer.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def is_mplayer
  @is_mplayer
end

#is_spotifyObject (readonly)

Returns the value of attribute is_spotify.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def is_spotify
  @is_spotify
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/terminal_player/site.rb', line 7

def name
  @name
end

#playerObject

Returns the value of attribute player.



6
7
8
# File 'lib/terminal_player/site.rb', line 6

def player
  @player
end

#songsObject

Returns the value of attribute songs.



6
7
8
# File 'lib/terminal_player/site.rb', line 6

def songs
  @songs
end

Instance Method Details

#playObject



44
45
46
# File 'lib/terminal_player/site.rb', line 44

def play
  @player.play
end

#song_changedObject



48
49
50
51
# File 'lib/terminal_player/site.rb', line 48

def song_changed
  changed
  notify_observers(Time.now, @songs)
end