class Xcunique::Parser
Parser
is responsible for traversing the project objects from the entry point provided and building a Hash
of visited notes which map old UUID to path of node.
Nodes that have already been visited are skipped
Attributes
objects[RW]
project[RW]
visited[R]
@!attribute [r] visited
@return [Hash] a mapping of old UUID to the of where the node is situated
Public Class Methods
new(project)
click to toggle source
@param project [Hash] the project to parse
# File lib/xcunique/parser.rb, line 14 def initialize project @project = project @objects = @project[Keys::OBJECTS] @visited = {} end
Public Instance Methods
parse(object:, path: "")
click to toggle source
Recursively traverse `object` building the `visited` Hash
by keeping track of the current path
Objects that have already been visited are skipped to avoid cycles or modifying existing values
@param object [Hash, Array, String] the current object to traverse @param path [String] the current path to this node
# File lib/xcunique/parser.rb, line 26 def parse object:, path: "" return if visited.has_key? object case object when Array object.each do |value| parse object: value, path: path end when Hash parse object: object.values, path: path when String current = objects[object] return if current.nil? || current[Keys::ISA].nil? path += '/' + current[Keys::ISA] + Helpers.resolve_attributes(object, objects) visited[object] = path parse object: current, path: path end end