Class: MetadataPresenter::PageAnswersPresenter
- Inherits:
-
Object
- Object
- MetadataPresenter::PageAnswersPresenter
- Defined in:
- app/presenters/metadata_presenter/page_answers_presenter.rb
Constant Summary collapse
- FIRST_ANSWER =
0
- NO_USER_INPUT =
%w[page.checkanswers page.confirmation page.content].freeze
Instance Attribute Summary collapse
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Class Method Summary collapse
Instance Method Summary collapse
- #answer ⇒ Object
- #display_heading?(index) ⇒ Boolean
-
#initialize(view:, component:, page:, answers:) ⇒ PageAnswersPresenter
constructor
A new instance of PageAnswersPresenter.
Constructor Details
#initialize(view:, component:, page:, answers:) ⇒ PageAnswersPresenter
Returns a new instance of PageAnswersPresenter.
28 29 30 31 32 33 34 35 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 28 def initialize(view:, component:, page:, answers:) @view = view @component = component @page = page @answers = answers @page_answers = PageAnswers.new(page, answers) end |
Instance Attribute Details
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
23 24 25 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 23 def answers @answers end |
#component ⇒ Object (readonly)
Returns the value of attribute component.
23 24 25 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 23 def component @component end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
23 24 25 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 23 def page @page end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
23 24 25 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 23 def view @view end |
Class Method Details
.map(view:, pages:, answers:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 6 def self.map(view:, pages:, answers:) user_input_pages(pages).map { |page| Array(page.components).map do |component| new( view: view, component: component, page: page, answers: answers ) end }.reject(&:empty?) end |
.user_input_pages(pages) ⇒ Object
19 20 21 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 19 def self.user_input_pages(pages) pages.reject { |page| page.type.in?(NO_USER_INPUT) } end |
Instance Method Details
#answer ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 37 def answer value = @page_answers.send(component.id) return '' if value.blank? if self.class.private_method_defined?(component.type.to_sym) send(component.type.to_sym, value) else value end end |
#display_heading?(index) ⇒ Boolean
49 50 51 |
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 49 def display_heading?(index) page.type == 'page.multiplequestions' && index == FIRST_ANSWER end |