Class: SLComponents::BuildViewer

Inherits:
Object
  • Object
show all
Defined in:
lib/mk_semi_lattice/sl_components.rb

Overview

SLComponents::GraphData はノードとエッジのデータをYAMLファイルから読み込み作成

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = "dir_node_edge.yaml", options) ⇒ BuildViewer

Returns a new instance of BuildViewer.



310
311
312
313
314
315
316
317
318
319
320
# File 'lib/mk_semi_lattice/sl_components.rb', line 310

def initialize(file = "dir_node_edge.yaml", options)
  with_semi_lattice_yaml = options[:with_semi_lattice_yaml]
  show_index = options[:show_index]
  @nodes = []
  @edges = []
  @node_table = {}
  @selected = nil
  @shift_pressed = false
  @show_index = show_index
  load_yaml_data_with_state(file, with_semi_lattice_yaml: with_semi_lattice_yaml)
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



307
308
309
# File 'lib/mk_semi_lattice/sl_components.rb', line 307

def edges
  @edges
end

#node_tableObject (readonly)

Returns the value of attribute node_table.



307
308
309
# File 'lib/mk_semi_lattice/sl_components.rb', line 307

def node_table
  @node_table
end

#nodesObject (readonly)

Returns the value of attribute nodes.



307
308
309
# File 'lib/mk_semi_lattice/sl_components.rb', line 307

def nodes
  @nodes
end

#selectedObject

Returns the value of attribute selected.



308
309
310
# File 'lib/mk_semi_lattice/sl_components.rb', line 308

def selected
  @selected
end

#shift_pressedObject

Returns the value of attribute shift_pressed.



308
309
310
# File 'lib/mk_semi_lattice/sl_components.rb', line 308

def shift_pressed
  @shift_pressed
end

#show_indexObject

Returns the value of attribute show_index.



308
309
310
# File 'lib/mk_semi_lattice/sl_components.rb', line 308

def show_index
  @show_index
end

Instance Method Details

#add_edge(from_id, to_id) ⇒ Object



329
330
331
332
333
# File 'lib/mk_semi_lattice/sl_components.rb', line 329

def add_edge(from_id, to_id)
  from = @node_table[from_id]
  to = @node_table[to_id]
  @edges << Edge.new(from, to) if from && to
end

#add_node(node_data) ⇒ Object



322
323
324
325
326
327
# File 'lib/mk_semi_lattice/sl_components.rb', line 322

def add_node(node_data)
  return if node_data[:id].nil?
  n = Node.new(node_data)
  @nodes << n
  @node_table[node_data[:id]] = n
end

#load_yaml_data_with_state(path, with_semi_lattice_yaml: false) ⇒ Object



335
336
337
338
339
340
341
342
343
344
# File 'lib/mk_semi_lattice/sl_components.rb', line 335

def load_yaml_data_with_state(path, with_semi_lattice_yaml: false)
  state_file = path
  data = if with_semi_lattice_yaml && File.exist?(state_file)
           YAML.load_file(state_file)
         else
           YAML.load_file(path, symbolize_names: true)
         end
  #p data
  load_nodes_and_edges(data)
end