Sha256: 43a47a2678c77aa03c64c79467268dc7091e35cf1ae52f7129ee150ed474a6cf

Contents?: true

Size: 958 Bytes

Versions: 154

Compression:

Stored size: 958 Bytes

Contents

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

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

    def each
      active.each do |problem|
        yield problem
      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_problems ||= exercise_slugs.map { |slug| Problem.new(slug, root) }
    end

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

    def by_slug
      @by_slug ||= problem_map
    end

    def problem_map
      hash = Hash.new { |_, k| Problem.new(k, root) }
      active.each do |problem|
        hash[problem.slug] = problem
      end
      hash
    end
  end
end

Version data entries

154 entries across 154 versions & 1 rubygems

Version Path
trackler-2.1.0.24 lib/trackler/problems.rb
trackler-2.1.0.23 lib/trackler/problems.rb
trackler-2.1.0.22 lib/trackler/problems.rb
trackler-2.1.0.21 lib/trackler/problems.rb
trackler-2.1.0.20 lib/trackler/problems.rb
trackler-2.1.0.19 lib/trackler/problems.rb
trackler-2.1.0.18 lib/trackler/problems.rb
trackler-2.1.0.17 lib/trackler/problems.rb
trackler-2.1.0.16 lib/trackler/problems.rb
trackler-2.1.0.15 lib/trackler/problems.rb
trackler-2.1.0.14 lib/trackler/problems.rb
trackler-2.1.0.13 lib/trackler/problems.rb
trackler-2.1.0.12 lib/trackler/problems.rb
trackler-2.1.0.11 lib/trackler/problems.rb
trackler-2.1.0.10 lib/trackler/problems.rb
trackler-2.1.0.9 lib/trackler/problems.rb
trackler-2.1.0.8 lib/trackler/problems.rb
trackler-2.1.0.7 lib/trackler/problems.rb
trackler-2.1.0.6 lib/trackler/problems.rb
trackler-2.1.0.5 lib/trackler/problems.rb