Class: MetadataPresenter::Component
- Inherits:
-
Metadata
- Object
- Metadata
- MetadataPresenter::Component
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
Instance Method Details
#content? ⇒ 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_title ⇒ Object
13
14
15
|
# File 'app/models/metadata_presenter/component.rb', line 13
def humanised_title
label || legend
end
|
#items ⇒ Object
17
18
19
20
21
|
# File 'app/models/metadata_presenter/component.rb', line 17
def items
Array(metadata.items).map do |item|
MetadataPresenter::Item.new(item, editor: editor?)
end
end
|
#supported_validations ⇒ Object
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
25
26
27
|
# File 'app/models/metadata_presenter/component.rb', line 25
def supports_branching?
type.in?(SUPPORTS_BRANCHING)
end
|
#to_partial_path ⇒ Object
9
10
11
|
# File 'app/models/metadata_presenter/component.rb', line 9
def to_partial_path
"metadata_presenter/component/#{type}"
end
|
#upload? ⇒ Boolean
33
34
35
|
# File 'app/models/metadata_presenter/component.rb', line 33
def upload?
type == 'upload'
end
|