class Grom::Builder

Builds Grom::Node objects from a Grom::Reader instance.

@since 0.1.0 @attr_reader [Array] objects Grom::Node objects generated from n-triple data.

Attributes

objects[R]

Public Class Methods

new(reader, decorators = nil) click to toggle source

@param [Grom::Reader] reader a Grom::Reader instance populated with data. @param [Module] decorators a Module that answers to decorate_with_type(node, type)

# File lib/grom/builder.rb, line 11
def initialize(reader, decorators = nil)
  @reader = reader
  @decorators = decorators

  build_objects
end

Public Instance Methods

build_objects() click to toggle source

Builds and links Grom::Node objects from n-triple data.

@return [Array] array of linked Grom::Node objects.

# File lib/grom/builder.rb, line 21
def build_objects
  build_objects_by_subject
  link_objects

  @objects
end
build_objects_by_subject() click to toggle source

Builds Grom::Node objects from n-triple data grouping by their subject.

@return [Grom::Builder] an instance of self.

# File lib/grom/builder.rb, line 31
def build_objects_by_subject
  @objects = []
  @objects_by_subject = {}

  @reader.statements_by_subject.each do |subject, statements|
    object = Grom::Node.new(statements, @decorators)
    @objects_by_subject[subject] = object
    @objects << object
  end

  self
end