Class: MetadataPresenter::Service
- Inherits:
-
Metadata
- Object
- Metadata
- MetadataPresenter::Service
show all
- Defined in:
- app/models/metadata_presenter/service.rb
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
#branches ⇒ Object
12
13
14
|
# File 'app/models/metadata_presenter/service.rb', line 12
def branches
flow_objects.select { |flow| flow.type == 'flow.branch' }
end
|
#checkanswers_page ⇒ Object
71
72
73
74
75
|
# File 'app/models/metadata_presenter/service.rb', line 71
def checkanswers_page
@checkanswers_page ||= pages.find do |page|
page.type == 'page.checkanswers'
end
end
|
#conditionals ⇒ Object
20
21
22
|
# File 'app/models/metadata_presenter/service.rb', line 20
def conditionals
branches.map(&:conditionals).flatten
end
|
#confirmation_page ⇒ Object
65
66
67
68
69
|
# File 'app/models/metadata_presenter/service.rb', line 65
def confirmation_page
@confirmation_page ||= pages.find do |page|
page.type == 'page.confirmation'
end
end
|
#content_conditionals ⇒ Object
28
29
30
|
# File 'app/models/metadata_presenter/service.rb', line 28
def content_conditionals
pages.flat_map(&:content_components).flat_map(&:conditionals)
end
|
#content_expressions ⇒ Object
24
25
26
|
# File 'app/models/metadata_presenter/service.rb', line 24
def content_expressions
content_conditionals.flat_map(&:expressions)
end
|
#expressions ⇒ Object
16
17
18
|
# File 'app/models/metadata_presenter/service.rb', line 16
def expressions
conditionals.map(&:expressions).flatten
end
|
#find_page_by_url(url) ⇒ Object
52
53
54
|
# File 'app/models/metadata_presenter/service.rb', line 52
def find_page_by_url(url)
all_pages.find { |page| strip_slash(page.url) == strip_slash(url) }
end
|
#find_page_by_uuid(uuid) ⇒ Object
56
57
58
|
# File 'app/models/metadata_presenter/service.rb', line 56
def find_page_by_uuid(uuid)
all_pages.find { |page| page.uuid == uuid }
end
|
#flow_object(uuid) ⇒ Object
32
33
34
35
36
|
# File 'app/models/metadata_presenter/service.rb', line 32
def flow_object(uuid)
MetadataPresenter::Flow.new(uuid, metadata.flow[uuid])
rescue StandardError
nil
end
|
#flow_objects ⇒ Object
8
9
10
|
# File 'app/models/metadata_presenter/service.rb', line 8
def flow_objects
flow.map { |uuid, flow| MetadataPresenter::Flow.new(uuid, flow) }
end
|
77
78
79
|
# File 'app/models/metadata_presenter/service.rb', line 77
def meta
MetadataPresenter::Meta.new(configuration['meta'])
end
|
#next_page(from:) ⇒ Object
60
61
62
63
|
# File 'app/models/metadata_presenter/service.rb', line 60
def next_page(from:)
current_page = find_page_by_url(from)
pages[pages.index(current_page) + 1] if current_page.present?
end
|
#no_back_link?(current_page) ⇒ Boolean
81
82
83
84
85
|
# File 'app/models/metadata_presenter/service.rb', line 81
def no_back_link?(current_page)
current_page == start_page ||
current_page == confirmation_page ||
current_page.standalone?
end
|
#page_with_component(uuid) ⇒ Object
87
88
89
90
91
|
# File 'app/models/metadata_presenter/service.rb', line 87
def page_with_component(uuid)
pages.find do |page|
Array(page.all_components).any? { |component| component.uuid == uuid }
end
end
|
#pages ⇒ Object
2
3
4
5
6
|
# File 'app/models/metadata_presenter/service.rb', line 2
def pages
@pages ||= metadata.pages.map do |page|
MetadataPresenter::Page.new(page, editor: editor?)
end
end
|
#pages_with_conditional_content_for_page(uuid) ⇒ Object
93
94
95
96
97
|
# File 'app/models/metadata_presenter/service.rb', line 93
def pages_with_conditional_content_for_page(uuid)
pages.select do |page|
uuid.in? page.content_components_by_type('conditional').flat_map(&:conditionals).flat_map(&:expressions).map(&:page)
end
end
|
#pages_with_conditional_content_for_question(uuid) ⇒ Object
99
100
101
102
103
|
# File 'app/models/metadata_presenter/service.rb', line 99
def pages_with_conditional_content_for_question(uuid)
pages.select do |page|
uuid.in? page.content_components_by_type('conditional').flat_map(&:conditionals).flat_map(&:expressions).map(&:component)
end
end
|
#pages_with_conditional_content_for_question_option(uuid) ⇒ Object
105
106
107
108
109
|
# File 'app/models/metadata_presenter/service.rb', line 105
def pages_with_conditional_content_for_question_option(uuid)
pages.select do |page|
uuid.in? page.content_components_by_type('conditional').flat_map(&:conditionals).flat_map(&:expressions).map(&:field)
end
end
|
#service_slug ⇒ Object
48
49
50
|
# File 'app/models/metadata_presenter/service.rb', line 48
def service_slug
service_name.gsub(/['’]/, '').parameterize
end
|
#standalone_pages ⇒ Object
38
39
40
41
42
|
# File 'app/models/metadata_presenter/service.rb', line 38
def standalone_pages
@standalone_pages ||= metadata.standalone_pages.map do |page|
MetadataPresenter::Page.new(page, editor: editor?)
end
end
|
#start_page ⇒ Object
44
45
46
|
# File 'app/models/metadata_presenter/service.rb', line 44
def start_page
pages.find { |page| page.type == 'page.start' }
end
|