Class: MetadataPresenter::Component

Inherits:
Metadata
  • Object
show all
Defined in:
app/models/metadata_presenter/component.rb

Constant Summary collapse

VALIDATION_BUNDLES =
{
  'date' => 'date',
  'number' => 'number',
  'text' => 'string',
  'textarea' => 'string'
}.freeze
SUPPORTS_BRANCHING =
%w[radios checkboxes].freeze

Instance Attribute Summary

Attributes inherited from Metadata

#metadata

Instance Method Summary collapse

Methods inherited from Metadata

#==, #editor?, #id, #initialize, #method_missing, #respond_to_missing?, #to_json, #type, #uuid

Constructor Details

This class inherits a constructor from MetadataPresenter::Metadata

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MetadataPresenter::Metadata

Instance Method Details

#content?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/metadata_presenter/component.rb', line 29

def content?
  type == 'content'
end

#find_item_by_uuid(uuid) ⇒ Object



37
38
39
# File 'app/models/metadata_presenter/component.rb', line 37

def find_item_by_uuid(uuid)
  items.find { |item| item.uuid == uuid }
end

#humanised_titleObject



13
14
15
# File 'app/models/metadata_presenter/component.rb', line 13

def humanised_title
  label || legend
end

#itemsObject



17
18
19
20
21
# File 'app/models/metadata_presenter/component.rb', line 17

def items
  Array(.items).map do |item|
    MetadataPresenter::Item.new(item, editor: editor?)
  end
end

#supported_validationsObject



41
42
43
44
45
46
47
# File 'app/models/metadata_presenter/component.rb', line 41

def supported_validations
  return [] if validation_bundle_key.nil?

  JSON::Validator.schema_for_uri(validation_bundle_key)
                 .schema['properties']['validation']['properties']
                 .keys
end

#supports_branching?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/metadata_presenter/component.rb', line 25

def supports_branching?
  type.in?(SUPPORTS_BRANCHING)
end

#to_partial_pathObject



9
10
11
# File 'app/models/metadata_presenter/component.rb', line 9

def to_partial_path
  "metadata_presenter/component/#{type}"
end

#upload?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/metadata_presenter/component.rb', line 33

def upload?
  type == 'upload'
end