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
63
64
65
66
67
|
# File 'app/models/metadata_presenter/service.rb', line 63
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
57
58
59
60
61
|
# File 'app/models/metadata_presenter/service.rb', line 57
def confirmation_page
@confirmation_page ||= pages.find do |page|
page.type == 'page.confirmation'
end
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
44
45
46
|
# File 'app/models/metadata_presenter/service.rb', line 44
def find_page_by_url(url)
all_pages.find { |page| strip_slash(page.url) == strip_slash(url) }
end
|
#find_page_by_uuid(uuid) ⇒ Object
48
49
50
|
# File 'app/models/metadata_presenter/service.rb', line 48
def find_page_by_uuid(uuid)
all_pages.find { |page| page.uuid == uuid }
end
|
#flow_object(uuid) ⇒ Object
24
25
26
27
28
|
# File 'app/models/metadata_presenter/service.rb', line 24
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
|
69
70
71
|
# File 'app/models/metadata_presenter/service.rb', line 69
def meta
MetadataPresenter::Meta.new(configuration['meta'])
end
|
#next_page(from:) ⇒ Object
52
53
54
55
|
# File 'app/models/metadata_presenter/service.rb', line 52
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
73
74
75
76
77
|
# File 'app/models/metadata_presenter/service.rb', line 73
def no_back_link?(current_page)
current_page == start_page ||
current_page == confirmation_page ||
current_page.standalone?
end
|
#page_with_component(uuid) ⇒ Object
79
80
81
82
83
|
# File 'app/models/metadata_presenter/service.rb', line 79
def page_with_component(uuid)
pages.find do |page|
Array(page.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
|
#service_slug ⇒ Object
40
41
42
|
# File 'app/models/metadata_presenter/service.rb', line 40
def service_slug
service_name.gsub(/['’]/, '').parameterize
end
|
#standalone_pages ⇒ Object
30
31
32
33
34
|
# File 'app/models/metadata_presenter/service.rb', line 30
def standalone_pages
@standalone_pages ||= metadata.standalone_pages.map do |page|
MetadataPresenter::Page.new(page, editor: editor?)
end
end
|
#start_page ⇒ Object
36
37
38
|
# File 'app/models/metadata_presenter/service.rb', line 36
def start_page
pages.find { |page| page.type == 'page.start' }
end
|