Class: Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/lucidMachines/chart.rb

Overview

A chart is made of pages, blocks and links. Each block and links belong to a page. The links may or may not have blocks endpoints. The blocks may or may not have input / output blocks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChart

Returns a new instance of Chart.



10
11
12
13
14
# File 'lib/lucidMachines/chart.rb', line 10

def initialize
  @pages = {}
  @blocks = {}
  @links = {}
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



8
9
10
# File 'lib/lucidMachines/chart.rb', line 8

def blocks
  @blocks
end

Returns the value of attribute links.



8
9
10
# File 'lib/lucidMachines/chart.rb', line 8

def links
  @links
end

#pagesObject (readonly)

Returns the value of attribute pages.



8
9
10
# File 'lib/lucidMachines/chart.rb', line 8

def pages
  @pages
end

Instance Method Details

#add_block(b) ⇒ Object



56
# File 'lib/lucidMachines/chart.rb', line 56

def add_block(b) ;  @blocks[b.id] = b; end

#add_block!(block) ⇒ Object



133
134
135
# File 'lib/lucidMachines/chart.rb', line 133

def add_block!(block)
  @blocks.merge!(block)
end


59
# File 'lib/lucidMachines/chart.rb', line 59

def add_link(l) ;  @links[l.id] = l; end

#add_link!(link) ⇒ Object



137
138
139
# File 'lib/lucidMachines/chart.rb', line 137

def add_link!(link)
  @links.merge!(link)
end

#add_page(page) ⇒ Object



39
40
41
# File 'lib/lucidMachines/chart.rb', line 39

def add_page(page)
  @pages[page.id] = page
end

#add_page!(page) ⇒ Object



129
130
131
# File 'lib/lucidMachines/chart.rb', line 129

def add_page!(page)
  @pages.merge!(page)
end

#blocks_on_page(page) ⇒ Object



28
29
30
# File 'lib/lucidMachines/chart.rb', line 28

def blocks_on_page(page)
  @blocks.each_value.select{|b| b.page == page }
end

#check_initialObject

Warning, this logic should be elsewhere too application - oriented



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/lucidMachines/chart.rb', line 94

def check_initial
  @blocks.each_value do |b|
    next unless b.has_links?
    b.links_from.each_value do |b2|
      if b2.text.eql? "Initial"
        b2.hide
        b.set_initial
      end
    end
  end
end

#get_block(id) ⇒ Object



57
# File 'lib/lucidMachines/chart.rb', line 57

def get_block(id); @blocks[id] ; end

#get_blocks_of_type(type) ⇒ Object



32
33
34
35
36
# File 'lib/lucidMachines/chart.rb', line 32

def get_blocks_of_type(type)
  @blocks.each_value.select do |b|
    b.type.eql? type
  end
end


60
# File 'lib/lucidMachines/chart.rb', line 60

def get_link(id); @links[id] ; end

#get_page(id) ⇒ Object



43
44
45
# File 'lib/lucidMachines/chart.rb', line 43

def get_page(id)
  return @pages[id]
end

#has_block?(id) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/lucidMachines/chart.rb', line 62

def has_block?(id)
  @blocks.has_key? id
end

#page(name_to_find) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/lucidMachines/chart.rb', line 47

def page(name_to_find)
  out = @pages.values.select do |p|
    p.name.eql? name_to_find
  end

  return nil if out.empty?
  return out.first
end

replace text with objects



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/lucidMachines/chart.rb', line 79

def set_links
  @links.each_value do |link|
    source_block = get_block(link.source)
    destination_block = get_block(link.destination)

    next if source_block.nil? or destination_block.nil?
    
    source_block.link_to destination_block, link
    destination_block.link_from source_block, link
  end
end

#set_pagesObject

replace text with objects



67
68
69
70
71
72
73
74
75
76
# File 'lib/lucidMachines/chart.rb', line 67

def set_pages
  @pages.each_value do |page|
    @blocks.each_value do |block|
      page.set_block(block.id, block) if block.page_id == page.id
    end
    @links.each_value do |link|
      link.set_page(page) if link.page_id == page.id
    end
  end
end

#statesObject



20
21
22
# File 'lib/lucidMachines/chart.rb', line 20

def states
  @blocks.each_value.select{|b| b.is_state?}
end

#states_on_page(page) ⇒ Object



24
25
26
# File 'lib/lucidMachines/chart.rb', line 24

def states_on_page(page)
  @blocks.each_value.select{|b| b.is_state? and b.page == page }
end

#subchart_for_page(page) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/lucidMachines/chart.rb', line 107

def subchart_for_page(page)
  chart = Chart.new

  # add the page 
  chart.add_page!( { page.id => page} )

  # add the blocks of this page

  @blocks.each do |block_id, block|
    next unless block.page == page
    chart.add_block!({ block_id => block })
  end
  
  # add the links of this page
  @links.each do |link_id, link|
    next unless link.page == page
    chart.add_link!({ link_id => link })
  end

  return chart
end

#to_sObject



16
17
18
# File 'lib/lucidMachines/chart.rb', line 16

def to_s
  puts "Chart, #{@pages.length} pages."
end