Sha256: d07117bac226d9e3e24cc7ed8b04a42deb58c0d47065ada39e8a1904da1c6b65

Contents?: true

Size: 615 Bytes

Versions: 2

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true
module Nuva
  class ValenceRepository < Repository
    def initialize(data)
      super data
      @ancestor_ids_by_id = {}
      @data.each_value do |valence|
        # Build hash of ancestor IDs for valence
        @ancestor_ids_by_id[valence.id] = lookup_ancestors(valence).uniq
      end
      @ancestor_ids_by_id.freeze
    end

    def get_ancestor_ids(valence_id)
      @ancestor_ids_by_id[valence_id]
    end

    private

    def lookup_ancestors(valence)
      return [] if valence.nil?

      lookup_ancestors(find(valence.parent_id)) << valence.parent_id
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nuva-0.1.6 ./lib/repositories/valence_repository.rb
nuva-0.1.5 ./lib/repositories/valence_repository.rb