Module: Journeyviz::NodeGroup

Included in:
Block, Journey
Defined in:
lib/journeyviz/node_group.rb

Instance Method Summary collapse

Instance Method Details

#block(name, &definition) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/journeyviz/node_group.rb', line 9

def block(name, &definition)
  block = Block.new(name, self)

  @blocks ||= []
  if @blocks.any? { |defined_block| block.name == defined_block.name }
    raise DuplicatedDefinition, "Duplicated block name: #{name}"
  end

  @blocks.push(block)
  definition.call(block)
  block
end

#blocks(include_children: false) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/journeyviz/node_group.rb', line 22

def blocks(include_children: false)
  @blocks ||= []

  if include_children
    @blocks.flat_map { |block| [block] + block.blocks(include_children: true) }
  else
    @blocks
  end
end

#find_screen(qualifier) ⇒ Object



50
51
52
# File 'lib/journeyviz/node_group.rb', line 50

def find_screen(qualifier)
  screens.find { |screen| screen.full_qualifier == qualifier }
end

#inputsObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/journeyviz/node_group.rb', line 54

def inputs
  options = defined?(root_scope) && root_scope ? root_scope.screens : []
  external_screens = options - screens
  self_screens = screens
  external_screens.select do |screen|
    screen.actions.any? do |action|
      self_screens.include?(action.transition)
    end
  end
end

#outputsObject



65
66
67
68
69
70
71
# File 'lib/journeyviz/node_group.rb', line 65

def outputs
  screens
    .flat_map(&:actions)
    .map(&:transition)
    .compact
    .reject { |screen| screens.include?(screen) }
end

#screen(name) {|screen| ... } ⇒ Object

Yields:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/journeyviz/node_group.rb', line 32

def screen(name)
  @screens ||= []
  screen = Screen.new(name, self)

  if @screens.any? { |defined_screen| screen.name == defined_screen.name }
    raise DuplicatedDefinition, "Duplicated screen name: #{name}"
  end

  @screens.push(screen)
  yield screen if block_given?
  screen
end

#screensObject



45
46
47
48
# File 'lib/journeyviz/node_group.rb', line 45

def screens
  @screens ||= []
  @screens + blocks.flat_map(&:screens)
end