Class: BitPlayer::Navigator
- Inherits:
-
Object
- Object
- BitPlayer::Navigator
- Defined in:
- app/models/bit_player/navigator.rb
Overview
Business rules for proceeding statefully through an application.
Defined Under Namespace
Classes: RenderOptions
Instance Method Summary collapse
- #content_position ⇒ Object
- #context ⇒ Object
- #current_content_provider ⇒ Object
- #current_module ⇒ Object
- #fetch_next_content ⇒ Object
-
#initialize(participant) ⇒ Navigator
constructor
A new instance of Navigator.
- #initialize_context(context) ⇒ Object
- #initialize_location(options) ⇒ Object
- #module_position ⇒ Object
- #provider_position ⇒ Object
- #render_current_content(view_context) ⇒ Object
- #show_nav_link? ⇒ Boolean
Constructor Details
#initialize(participant) ⇒ Navigator
Returns a new instance of Navigator.
8 9 10 11 |
# File 'app/models/bit_player/navigator.rb', line 8 def initialize(participant) @participant = participant @status = participant. end |
Instance Method Details
#content_position ⇒ Object
25 26 27 |
# File 'app/models/bit_player/navigator.rb', line 25 def content_position @status.content_position end |
#context ⇒ Object
13 14 15 |
# File 'app/models/bit_player/navigator.rb', line 13 def context @status.context end |
#current_content_provider ⇒ Object
41 42 43 |
# File 'app/models/bit_player/navigator.rb', line 41 def current_content_provider current_module.provider(provider_position) end |
#current_module ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/bit_player/navigator.rb', line 72 def current_module @current_module ||= nil module_attrs = { bit_player_tool_id: Tool.find_by_title(context).try(:id), position: module_position } if current_module_stale? @current_module = ContentModule.where(module_attrs).first end @current_module ||= ContentModule.new(module_attrs) end |
#fetch_next_content ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/models/bit_player/navigator.rb', line 45 def fetch_next_content if current_content_provider.exists?(content_position + 1) @status.increment_content_position elsif current_module.provider_exists?(provider_position + 1) @status.increment_provider_position else initialize_context(context) end end |
#initialize_context(context) ⇒ Object
55 56 57 |
# File 'app/models/bit_player/navigator.rb', line 55 def initialize_context(context) @status.initialize_context(context) end |
#initialize_location(options) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/bit_player/navigator.rb', line 59 def initialize_location() content_module = ContentModule.find([:module_id]) @status.context = content_module.tool.title @status.module_position = content_module.position @status.provider_position = 1 if [:provider_id] @status.provider_position = content_module.content_providers .find([:provider_id]).position end @status.content_position = [[:content_position].to_i, 1].max @status.save end |
#module_position ⇒ Object
17 18 19 |
# File 'app/models/bit_player/navigator.rb', line 17 def module_position @status.module_position end |
#provider_position ⇒ Object
21 22 23 |
# File 'app/models/bit_player/navigator.rb', line 21 def provider_position @status.provider_position end |
#render_current_content(view_context) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/models/bit_player/navigator.rb', line 29 def render_current_content(view_context) = RenderOptions.new( view_context, context, content_position, @participant ) current_content_provider.render_current() end |
#show_nav_link? ⇒ Boolean
37 38 39 |
# File 'app/models/bit_player/navigator.rb', line 37 def show_nav_link? current_content_provider.show_nav_link? end |