Class: ChartLoader
- Inherits:
-
Object
- Object
- ChartLoader
- Defined in:
- lib/lucidMachines/loader.rb
Instance Attribute Summary collapse
-
#chart ⇒ Object
readonly
Returns the value of attribute chart.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Instance Method Summary collapse
- #create_entry(header, data) ⇒ Object
-
#initialize(name) ⇒ ChartLoader
constructor
A new instance of ChartLoader.
-
#load_all_blocks ⇒ Object
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.
- #load_links ⇒ Object
- #load_pages ⇒ Object
Constructor Details
#initialize(name) ⇒ ChartLoader
Returns a new instance of 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
#chart ⇒ Object (readonly)
Returns the value of attribute chart.
13 14 15 |
# File 'lib/lucidMachines/loader.rb', line 13 def chart @chart end |
#raw_data ⇒ Object (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_blocks ⇒ Object
def load_blocks
# It is a text type
blocks = @struct_data.select {|d| BlockTypes.any? d["Name"] }
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 |