Class: MetadataPresenter::AutocompleteValidator

Inherits:
BaseValidator show all
Defined in:
app/validators/metadata_presenter/autocomplete_validator.rb

Instance Attribute Summary collapse

Attributes inherited from BaseValidator

#component, #page_answers

Instance Method Summary collapse

Methods inherited from BaseValidator

#allow_blank?, #custom_error_message, #default_error_message, #error_key, #error_message_hash, #schema_key, #user_answer, #valid?, #validation_value

Constructor Details

#initialize(page_answers:, component:, autocomplete_items:) ⇒ AutocompleteValidator

Returns a new instance of AutocompleteValidator.



5
6
7
8
9
# File 'app/validators/metadata_presenter/autocomplete_validator.rb', line 5

def initialize(page_answers:, component:, autocomplete_items:)
  super(page_answers:, component:)

  @autocomplete_items = autocomplete_items
end

Instance Attribute Details

#autocomplete_itemsObject (readonly)

Returns the value of attribute autocomplete_items.



3
4
5
# File 'app/validators/metadata_presenter/autocomplete_validator.rb', line 3

def autocomplete_items
  @autocomplete_items
end

Instance Method Details

#autocomplete_item_listObject



17
18
19
# File 'app/validators/metadata_presenter/autocomplete_validator.rb', line 17

def autocomplete_item_list
  @autocomplete_item_list ||= autocomplete_items[component.uuid]
end

#invalid_answer?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'app/validators/metadata_presenter/autocomplete_validator.rb', line 11

def invalid_answer?
  return if autocomplete_item_list.blank?

  autocomplete_item_list.exclude?(JSON.parse(user_answer))
end