Class: ChartLoader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ChartLoader



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lucidMachines/loader.rb', line 15

def initialize(name)
  
  arr_of_arrs = CSV.read name

  @header = arr_of_arrs.first
  @raw_data = arr_of_arrs[1..-1]
  d = @raw_data.first
  
  @struct_data = arr_of_arrs[1..-1].map{ |d| create_entry(@header, d)}
  @chart = Chart.new

  # 1. Pages and Get rid of them...
  pages = load_pages
  @struct_data.reject!{ |d| pages.include? d }
  
  # 2. Containers
  # load_containers  ## TODO

  # Links, and get rid of them
  links = load_links
  @struct_data.reject!{ |d| links.include? d }

  # Blocks, and get rid of them
  blocks = load_all_blocks
  @struct_data.reject!{ |d| blocks.include? d }

  #      puts "Elements left: "  + @struct_data.size.to_s

  @chart.set_pages
  @chart.set_links
  @chart.check_initial
end

Instance Attribute Details

#chartObject (readonly)

Returns the value of attribute chart.



13
14
15
# File 'lib/lucidMachines/loader.rb', line 13

def chart
  @chart
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



13
14
15
# File 'lib/lucidMachines/loader.rb', line 13

def raw_data
  @raw_data
end

Instance Method Details

#create_entry(header, data) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/lucidMachines/loader.rb', line 49

def create_entry(header, data)
  output = {}
  data.each_with_index do |d, i|
    next unless d != nil
    output[header[i]] = d
  end
  output
end

#load_all_blocksObject

def load_blocks

It is a text type

blocks = @struct_data.select {|d| BlockTypes.any? d } blocks.map do |d| e = Block.new(d) @chart.add_block e d end end



78
79
80
81
82
83
84
85
# File 'lib/lucidMachines/loader.rb', line 78

def load_all_blocks
  # It is a text type
  blocks = @struct_data
  blocks.map do |d|
    @chart.add_block(Block.new(d))
    d
  end
end


87
88
89
90
91
92
93
# File 'lib/lucidMachines/loader.rb', line 87

def load_links
  links = @struct_data.select{|d| Links.any? d["Name"] }
  links.map do |d|
    @chart.add_link(Link.new(d))
    d
  end
end

#load_pagesObject



59
60
61
62
63
64
65
66
# File 'lib/lucidMachines/loader.rb', line 59

def load_pages
  pages_raw = @struct_data.select{|d| is_page? d }
  pages_raw.map do |d|
    p = Page.new(d)
    @chart.add_page p
    d
  end
end