Sha256: 73cd8aa05dd81ec4a9f1b3774e3e44ba5194e294354795554a64449a6896fbba

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

module Trackler
  # Specifications is the collection of problems that we have metadata for.
  class Specifications
    include Enumerable

    attr_reader :root
    def initialize(root)
      @root = root
    end

    def each
      active.each do |specification|
        yield specification
      end
    end

    def [](slug)
      by_slug[slug]
    end

    # rubocop:disable Style/OpMethod
    def -(slugs)
      (by_slug.keys - slugs).sort
    end

    private

    def active
      @active ||= all.select(&:active?)
    end

    def all
      @all_specifications ||= exercise_slugs.map { |slug| Specification.new(slug, root) }
    end

    def exercise_slugs
      Dir["%s/common/exercises/*/" % root].map { |path| File.basename(path) }.sort
    end

    def by_slug
      @by_slug ||= specification_map
    end

    def specification_map
      hash = Hash.new { |_, k| Specification.new(k, root) }
      active.each do |specification|
        hash[specification.slug] = specification
      end
      hash
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trackler-2.1.0.48 lib/trackler/specifications.rb
trackler-2.1.0.47 lib/trackler/specifications.rb
trackler-2.1.0.46 lib/trackler/specifications.rb
trackler-2.1.0.45 lib/trackler/specifications.rb
trackler-2.1.0.44 lib/trackler/specifications.rb
trackler-2.1.0.43 lib/trackler/specifications.rb
trackler-2.1.0.42 lib/trackler/specifications.rb
trackler-2.1.0.41 lib/trackler/specifications.rb
trackler-2.1.0.40 lib/trackler/specifications.rb
trackler-2.1.0.39 lib/trackler/specifications.rb
trackler-2.1.0.38 lib/trackler/specifications.rb
trackler-2.1.0.37 lib/trackler/specifications.rb
trackler-2.1.0.36 lib/trackler/specifications.rb
trackler-2.1.0.34 lib/trackler/specifications.rb
trackler-2.1.0.33 lib/trackler/specifications.rb
trackler-2.1.0.32 lib/trackler/specifications.rb
trackler-2.1.0.31 lib/trackler/specifications.rb
trackler-2.1.0.30 lib/trackler/specifications.rb
trackler-2.1.0.29 lib/trackler/specifications.rb
trackler-2.1.0.28 lib/trackler/specifications.rb