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
- #fetch_previous_content ⇒ Object
-
#initialize(participant) ⇒ Navigator
constructor
A new instance of Navigator.
- #initialize_context(context) ⇒ Object
- #initialize_location(options) ⇒ Object
- #module_position ⇒ Object
- #previous_content? ⇒ Boolean
- #provider_position ⇒ Object
- #render_current_content(view_context) ⇒ Object
- #show_nav_link? ⇒ Boolean
Constructor Details
#initialize(participant) ⇒ Navigator
Returns a new instance of Navigator.
10 11 12 13 |
# File 'app/models/bit_player/navigator.rb', line 10 def initialize(participant) @participant = participant @status = participant. end |
Instance Method Details
#content_position ⇒ Object
27 28 29 |
# File 'app/models/bit_player/navigator.rb', line 27 def content_position @status.content_position end |
#context ⇒ Object
15 16 17 |
# File 'app/models/bit_player/navigator.rb', line 15 def context @status.context end |
#current_content_provider ⇒ Object
43 44 45 |
# File 'app/models/bit_player/navigator.rb', line 43 def current_content_provider current_module.provider(provider_position) end |
#current_module ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/bit_player/navigator.rb', line 84 def current_module @current_module ||= nil module_attrs = { bit_core_tool_id: BitCore::Tool.find_by_title(context).try(:id), position: module_position } if current_module_stale? @current_module = BitCore::ContentModule.where(module_attrs).first end @current_module ||= BitCore::ContentModule.new(module_attrs) end |
#fetch_next_content ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/bit_player/navigator.rb', line 47 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 |
#fetch_previous_content ⇒ Object
57 58 59 60 61 |
# File 'app/models/bit_player/navigator.rb', line 57 def fetch_previous_content if previous_content? @status.decrement_content_position end end |
#initialize_context(context) ⇒ Object
67 68 69 |
# File 'app/models/bit_player/navigator.rb', line 67 def initialize_context(context) @status.initialize_context(context) end |
#initialize_location(options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/bit_player/navigator.rb', line 71 def initialize_location() content_module = BitCore::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
19 20 21 |
# File 'app/models/bit_player/navigator.rb', line 19 def module_position @status.module_position end |
#previous_content? ⇒ Boolean
63 64 65 |
# File 'app/models/bit_player/navigator.rb', line 63 def previous_content? current_content_provider.exists?(content_position - 1) end |
#provider_position ⇒ Object
23 24 25 |
# File 'app/models/bit_player/navigator.rb', line 23 def provider_position @status.provider_position end |
#render_current_content(view_context) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/models/bit_player/navigator.rb', line 31 def render_current_content(view_context) = RenderOptions.new( view_context, context, content_position, @participant ) current_content_provider.render_current() end |
#show_nav_link? ⇒ Boolean
39 40 41 |
# File 'app/models/bit_player/navigator.rb', line 39 def show_nav_link? current_content_provider.show_nav_link? end |