Class: Soundcloud2000::Controllers::TrackController

Inherits:
Controller
  • Object
show all
Defined in:
lib/soundcloud2000/controllers/track_controller.rb

Instance Attribute Summary

Attributes inherited from Controller

#events

Instance Method Summary collapse

Methods inherited from Controller

#render

Constructor Details

#initialize(view, client) ⇒ TrackController

Returns a new instance of TrackController.



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
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 12

def initialize(view, client)
  super(view)

  @client = client

  events.on(:key) do |key|
    case key
    when :enter
      @view.select
      events.trigger(:select, current_track)
    when :up, :k
      @view.up
    when :down, :j
      @view.down
      @tracks.load_more if @view.bottom?
    when :u
      @tracks.user = fetch_user_with_message('Change to SoundCloud user: ')
      @tracks.collection_to_load = :user
      @tracks.clear_and_replace
    when :f
      if @tracks.user.nil?
        @tracks.user = fetch_user_with_message('Change to favorites from SoundCloud user: ')
      end
      @tracks.collection_to_load = :favorites
      @tracks.clear_and_replace
    when :s
      @view.clear
      if @tracks.user.nil?
        @tracks.user = fetch_user_with_message('Change to SoundCloud user: ')
      end
      set = UI::Input.getstr('Change to SoundCloud playlist: ')
      @tracks.playlist = Models::Playlist.new(@client.resolve(@tracks.user.permalink + '/sets/' + set))
      @tracks.collection_to_load = :playlist
      @tracks.clear_and_replace
    end
  end
end

Instance Method Details

#bind_to(tracks) ⇒ Object



64
65
66
67
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 64

def bind_to(tracks)
  @tracks = tracks
  @view.bind_to(tracks)
end

#current_trackObject



60
61
62
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 60

def current_track
  @tracks[@view.current]
end

#fetch_user_with_message(message_to_display) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 50

def fetch_user_with_message(message_to_display)
  permalink = UI::Input.getstr(message_to_display)
  user_hash = @client.resolve(permalink)
  if user_hash
    Models::User.new(user_hash)
  else
    nil
  end
end

#loadObject



69
70
71
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 69

def load
  @tracks.load
end

#next_trackObject



73
74
75
76
77
# File 'lib/soundcloud2000/controllers/track_controller.rb', line 73

def next_track
  @view.down
  @view.select
  events.trigger(:select, current_track)
end