class Hashematics::Graph

Graph serves as the main point of entry for this system. Basic use:

  1. Initialize a Graph by passing in an array of groups (tree structures)

  2. Feed in objects into the graph using the add method

  3. Use the groups, records, and objects methods to interact with the generated object graph.

Attributes

group_dictionary[R]
record_set[R]

Public Class Methods

new(groups = []) click to toggle source
# File lib/hashematics/graph.rb, line 23
def initialize(groups = [])
  @group_dictionary = Dictionary.new.add(groups, &:name)
  @record_set       = RecordSet.new

  freeze
end

Public Instance Methods

add(enumerable) click to toggle source
# File lib/hashematics/graph.rb, line 30
def add(enumerable)
  enumerable.each { |object| add_one(object) }

  self
end
children() click to toggle source
# File lib/hashematics/graph.rb, line 36
def children
  group_dictionary.map(&:name)
end
data(name) click to toggle source
# File lib/hashematics/graph.rb, line 44
def data(name)
  visit(name).map { |v| v.data(true) }
end
visit(name) click to toggle source
# File lib/hashematics/graph.rb, line 40
def visit(name)
  group(name)&.visit || []
end

Private Instance Methods

add_one(object) click to toggle source
# File lib/hashematics/graph.rb, line 54
def add_one(object)
  record = record_set.add(object)

  group_dictionary.each do |group|
    group.add(record)
  end
end
group(name) click to toggle source
# File lib/hashematics/graph.rb, line 50
def group(name)
  group_dictionary.get(name)
end