Sha256: 5ec2a85df4e2a9d0ce81a912bfb5a195dc7d2a1d96464ee18dce3fc9ffdc73a7

Contents?: true

Size: 931 Bytes

Versions: 53

Compression:

Stored size: 931 Bytes

Contents

module Trackler
  # Implementations is a collection of exercises in a specific language track.
  class Implementations
    include Enumerable

    attr_reader :repo, :slugs, :root, :track
    def initialize(repo, slugs, root, track)
      @repo = repo
      @slugs = slugs
      @root = root
      @track = track
    end

    def each
      all.each do |implementation|
        yield implementation
      end
    end

    def [](slug)
      by_slug[slug]
    end

    private

    def all
      @all ||= slugs.map { |slug|
        Implementation.new(track.id, repo, Problem.new(slug, root, track), root)
      }
    end

    def by_slug
      @by_slug ||= implementation_map
    end

    def implementation_map
      hash = Hash.new { |_, k|
        Implementation.new(track.id, repo, Problem.new(k, root, track), root)
      }
      all.each do |impl|
        hash[impl.problem.slug] = impl
      end
      hash
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
trackler-2.0.8.54 lib/trackler/implementations.rb
trackler-2.0.8.53 lib/trackler/implementations.rb
trackler-2.0.8.52 lib/trackler/implementations.rb
trackler-2.0.8.51 lib/trackler/implementations.rb
trackler-2.0.8.50 lib/trackler/implementations.rb
trackler-2.0.8.49 lib/trackler/implementations.rb
trackler-2.0.8.48 lib/trackler/implementations.rb
trackler-2.0.8.47 lib/trackler/implementations.rb
trackler-2.0.8.46 lib/trackler/implementations.rb
trackler-2.0.8.45 lib/trackler/implementations.rb
trackler-2.0.8.44 lib/trackler/implementations.rb
trackler-2.0.8.43 lib/trackler/implementations.rb
trackler-2.0.8.42 lib/trackler/implementations.rb
trackler-2.0.8.41 lib/trackler/implementations.rb
trackler-2.0.8.40 lib/trackler/implementations.rb
trackler-2.0.8.39 lib/trackler/implementations.rb
trackler-2.0.8.38 lib/trackler/implementations.rb
trackler-2.0.8.37 lib/trackler/implementations.rb
trackler-2.0.8.36 lib/trackler/implementations.rb
trackler-2.0.8.35 lib/trackler/implementations.rb