Class: MetadataPresenter::Grid

Inherits:
Object
  • Object
show all
Includes:
BranchDestinations
Defined in:
app/models/metadata_presenter/grid.rb

Constant Summary collapse

ROW_ZERO =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BranchDestinations

#exiting_destinations_from_branch, #has_or_conditionals?

Constructor Details

#initialize(service, start_from: nil, main_flow: []) ⇒ Grid

Returns a new instance of Grid.



24
25
26
27
28
29
30
31
32
33
# File 'app/models/metadata_presenter/grid.rb', line 24

def initialize(service, start_from: nil, main_flow: [])
  @service = service
  @start_from = start_from
  @main_flow = main_flow
  @ordered = []
  @routes = []
  @traversed = []
  @coordinates = MetadataPresenter::Coordinates.new(service)
  @previous_uuids = {}
end

Instance Attribute Details

#previous_uuidsObject

Returns the value of attribute previous_uuids.



22
23
24
# File 'app/models/metadata_presenter/grid.rb', line 22

def previous_uuids
  @previous_uuids
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'app/models/metadata_presenter/grid.rb', line 22

def service
  @service
end

#start_fromObject (readonly)

Returns the value of attribute start_from.



22
23
24
# File 'app/models/metadata_presenter/grid.rb', line 22

def start_from
  @start_from
end

Instance Method Details

#buildObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/metadata_presenter/grid.rb', line 37

def build
  return @ordered unless @ordered.empty?

  @ordered = make_grid
  set_column_numbers
  set_row_numbers
  set_previous_uuids
  add_by_coordinates
  insert_expression_spacers
  trim_pointers unless main_flow.empty? # only used by detached grids
  trim_spacers
  insert_warning if main_flow.empty?

  @ordered = @ordered.reject(&:empty?)
end

#conditional_uuid_for_object(uuid) ⇒ Object



82
83
84
85
86
# File 'app/models/metadata_presenter/grid.rb', line 82

def conditional_uuid_for_object(uuid)
  return unless previous_uuids.key?(uuid)

  previous_uuids[uuid][:conditional_uuid]
end

#flow_uuidsObject



64
65
66
# File 'app/models/metadata_presenter/grid.rb', line 64

def flow_uuids
  ordered_flow.map(&:uuid)
end

#ordered_flowObject



53
54
55
56
57
58
# File 'app/models/metadata_presenter/grid.rb', line 53

def ordered_flow
  @ordered_flow ||=
    build.flatten.reject do |obj|
      obj.is_a?(MetadataPresenter::Spacer) || obj.is_a?(MetadataPresenter::Warning)
    end
end

#ordered_pagesObject



60
61
62
# File 'app/models/metadata_presenter/grid.rb', line 60

def ordered_pages
  @ordered_pages ||= ordered_flow.reject(&:branch?)
end

#page_uuidsObject



68
69
70
# File 'app/models/metadata_presenter/grid.rb', line 68

def page_uuids
  ordered_pages.map(&:uuid)
end

#previous_uuid_for_object(uuid) ⇒ Object



76
77
78
79
80
# File 'app/models/metadata_presenter/grid.rb', line 76

def previous_uuid_for_object(uuid)
  return unless previous_uuids.key?(uuid)

  previous_uuids[uuid][:previous_flow_uuid]
end

#show_warning?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/metadata_presenter/grid.rb', line 72

def show_warning?
  checkanswers_warning.show_warning? || confirmation_warning.show_warning?
end