Class: MetadataPresenter::PageAnswersPresenter

Inherits:
Object
  • Object
show all
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
  page.start
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view:, component:, page:, answers:) ⇒ PageAnswersPresenter

Returns a new instance of PageAnswersPresenter.



33
34
35
36
37
38
39
40
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 33

def initialize(view:, component:, page:, answers:)
  @view = view
  @component = component
  @page = page
  @answers = answers

  @page_answers = PageAnswers.new(page, answers)
end

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



28
29
30
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 28

def answers
  @answers
end

#componentObject (readonly)

Returns the value of attribute component.



28
29
30
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 28

def component
  @component
end

#pageObject (readonly)

Returns the value of attribute page.



28
29
30
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 28

def page
  @page
end

#viewObject (readonly)

Returns the value of attribute view.



28
29
30
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 28

def view
  @view
end

Class Method Details

.map(view:, pages:, answers:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 11

def self.map(view:, pages:, answers:)
  user_input_pages(pages).map { |page|
    Array(page.supported_components_by_type(:input)).map do |component|
      new(
        view:,
        component:,
        page:,
        answers:
      )
    end
  }.reject(&:empty?)
end

.user_input_pages(pages) ⇒ Object



24
25
26
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 24

def self.user_input_pages(pages)
  pages.reject { |page| page.type.in?(NO_USER_INPUT) }
end

Instance Method Details

#answerObject



42
43
44
45
46
47
48
49
50
51
52
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 42

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

Returns:

  • (Boolean)


54
55
56
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 54

def display_heading?(index)
  multiplequestions_page? && index == FIRST_ANSWER
end

#last_multiple_question?(index, presenters_count_for_page) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/presenters/metadata_presenter/page_answers_presenter.rb', line 58

def last_multiple_question?(index, presenters_count_for_page)
  multiplequestions_page? && index == presenters_count_for_page - 1
end