Class: Rubio::Model::RadioPresenter
- Inherits:
-
Object
- Object
- Rubio::Model::RadioPresenter
- Defined in:
- lib/rubio/model/radio_presenter.rb
Overview
This is a presenter for the Radio view, which is an advanced controller
Instance Attribute Summary collapse
-
#current_station ⇒ Object
Returns the value of attribute current_station.
-
#initial_height ⇒ Object
readonly
Returns the value of attribute initial_height.
-
#initial_width ⇒ Object
readonly
Returns the value of attribute initial_width.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#stations ⇒ Object
Returns the value of attribute stations.
-
#view ⇒ Object
Returns the value of attribute view.
-
#window_height ⇒ Object
Returns the value of attribute window_height.
Instance Method Summary collapse
- #fetch_more_stations ⇒ Object
-
#initialize(options = {}) ⇒ RadioPresenter
constructor
Initializes with view options below: :backend, :initial_width, :initial_height, :radio_station_count, :debug, :show_menu, :show_page_count, :show_bookmarks, :show_margins :gradually_fetch_stations, :table_per_page.
- #play_station ⇒ Object
- #select_station(station) ⇒ Object
- #stations_incomplete? ⇒ Boolean
- #stop_station ⇒ Object
- #toggle_bookmarked_station(station) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RadioPresenter
Initializes with view options below: :backend, :initial_width, :initial_height, :radio_station_count, :debug, :show_menu, :show_page_count, :show_bookmarks, :show_margins :gradually_fetch_stations, :table_per_page
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubio/model/radio_presenter.rb', line 17 def initialize( = {}) @options = @options[:radio_station_count] = 1_000_000 if [:radio_station_count] == -1 @loaded_station_count = [[:gradually_fetch_stations] ? 100 : [:radio_station_count], [:radio_station_count]].min @loaded_station_offset = 0 @stations = Model::RadioBrowser.topvote(@loaded_station_count, offset: @loaded_station_offset) @player = Model::Player.new([:backend], show_currently_playing: [:show_currently_playing]) @initial_width = ([:initial_width] || ([:show_bookmarks] ? 740 : 620)).to_i @initial_height = ([:initial_height] || calculate_initial_height).to_i @window_height = @initial_height @view = :all Glimmer::DataBinding::Observer::Proc.new do self.window_height = calculate_initial_height end.observe(@player, :currently_playing) end |
Instance Attribute Details
#current_station ⇒ Object
Returns the value of attribute current_station.
11 12 13 |
# File 'lib/rubio/model/radio_presenter.rb', line 11 def current_station @current_station end |
#initial_height ⇒ Object (readonly)
Returns the value of attribute initial_height.
10 11 12 |
# File 'lib/rubio/model/radio_presenter.rb', line 10 def initial_height @initial_height end |
#initial_width ⇒ Object (readonly)
Returns the value of attribute initial_width.
10 11 12 |
# File 'lib/rubio/model/radio_presenter.rb', line 10 def initial_width @initial_width end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/rubio/model/radio_presenter.rb', line 10 def @options end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
10 11 12 |
# File 'lib/rubio/model/radio_presenter.rb', line 10 def player @player end |
#stations ⇒ Object
Returns the value of attribute stations.
11 12 13 |
# File 'lib/rubio/model/radio_presenter.rb', line 11 def stations @stations end |
#view ⇒ Object
Returns the value of attribute view.
11 12 13 |
# File 'lib/rubio/model/radio_presenter.rb', line 11 def view @view end |
#window_height ⇒ Object
Returns the value of attribute window_height.
11 12 13 |
# File 'lib/rubio/model/radio_presenter.rb', line 11 def window_height @window_height end |
Instance Method Details
#fetch_more_stations ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/rubio/model/radio_presenter.rb', line 71 def fetch_more_stations @loaded_station_offset += @loaded_station_count @loaded_station_count *= 2 new_station_count = [@loaded_station_count, [:radio_station_count] - @loaded_station_offset].min old_station_count = @stations.count self.stations += Model::RadioBrowser.topvote(new_station_count, offset: @loaded_station_offset) @all_stations_fetched = @stations.count == old_station_count self.stations end |
#play_station ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rubio/model/radio_presenter.rb', line 51 def play_station @player.play(current_station.url, station_name: current_station.name) current_station. = true rescue => e self.current_station = nil raise e end |
#select_station(station) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubio/model/radio_presenter.rb', line 34 def select_station(station) = station. stop_station self.current_station = station if self.current_station = nil else play_station end end |
#stations_incomplete? ⇒ Boolean
67 68 69 |
# File 'lib/rubio/model/radio_presenter.rb', line 67 def stations_incomplete? !@all_stations_fetched && @stations.count < [:radio_station_count] end |
#stop_station ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/rubio/model/radio_presenter.rb', line 59 def stop_station return if current_station.nil? @player.stop current_station. = false self.current_station = nil end |
#toggle_bookmarked_station(station) ⇒ Object
45 46 47 48 49 |
# File 'lib/rubio/model/radio_presenter.rb', line 45 def toggle_bookmarked_station(station) return unless station station.bookmarked = !station.bookmarked? end |