Class: MetadataPresenter::PageAnswers
- Inherits:
-
Object
- Object
- MetadataPresenter::PageAnswers
- Includes:
- ActionView::Helpers, ActiveModel::Model, ActiveModel::Validations
- Defined in:
- app/models/metadata_presenter/page_answers.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
-
#autocomplete_items ⇒ Object
readonly
Returns the value of attribute autocomplete_items.
-
#count ⇒ Object
Returns the value of attribute count.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#uploaded_files ⇒ Object
readonly
Returns the value of attribute uploaded_files.
Instance Method Summary collapse
-
#initialize(page, answers, autocomplete_items = nil) ⇒ PageAnswers
constructor
A new instance of PageAnswers.
- #method_missing(method_name, *_args) ⇒ Object
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
- #validate_answers ⇒ Object
Constructor Details
#initialize(page, answers, autocomplete_items = nil) ⇒ PageAnswers
Returns a new instance of PageAnswers.
9 10 11 12 13 14 |
# File 'app/models/metadata_presenter/page_answers.rb', line 9 def initialize(page, answers, autocomplete_items = nil) @page = page @answers = answers @autocomplete_items = autocomplete_items @uploaded_files = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/metadata_presenter/page_answers.rb', line 26 def method_missing(method_name, *_args) component = components.find { |c| c.id == method_name.to_s } if component && component.type == 'date' date_answer(component.id) elsif component && component.type == 'upload' upload_answer(component.id, count) elsif component && component.type == 'multiupload' answer_object = multiupload_answer(component.id, count) answer_object.to_h if answer_object.present? elsif component && component.type == 'checkboxes' answers[method_name.to_s].to_a elsif component && component.type == 'address' address_answer(method_name.to_s) else sanitize(answers[method_name.to_s]) end end |
Instance Attribute Details
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
6 7 8 |
# File 'app/models/metadata_presenter/page_answers.rb', line 6 def answers @answers end |
#autocomplete_items ⇒ Object (readonly)
Returns the value of attribute autocomplete_items.
6 7 8 |
# File 'app/models/metadata_presenter/page_answers.rb', line 6 def autocomplete_items @autocomplete_items end |
#count ⇒ Object
Returns the value of attribute count.
7 8 9 |
# File 'app/models/metadata_presenter/page_answers.rb', line 7 def count @count end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'app/models/metadata_presenter/page_answers.rb', line 6 def page @page end |
#uploaded_files ⇒ Object (readonly)
Returns the value of attribute uploaded_files.
6 7 8 |
# File 'app/models/metadata_presenter/page_answers.rb', line 6 def uploaded_files @uploaded_files end |
Instance Method Details
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
22 23 24 |
# File 'app/models/metadata_presenter/page_answers.rb', line 22 def respond_to_missing?(method_name, _include_private = false) method_name.to_s.in?(components.map(&:id)) end |
#validate_answers ⇒ Object
16 17 18 |
# File 'app/models/metadata_presenter/page_answers.rb', line 16 def validate_answers ValidateAnswers.new(self, components:, autocomplete_items:).valid? end |