class Mummy::Test

Attributes

items[R]
starred[R]

Public Class Methods

from_file(path, options = {}) click to toggle source
# File lib/mummy/test.rb, line 3
def self.from_file(path, options = {})
  extension = File.extname(path)
  input = File.read(path)

  if options[:parser]
    parser = Mummy::Constants::Parsers::NAMES[options[:parser].downcase]
    raise "The specified parser, #{options[:parser]}, does not exist" unless parser

    items = parser.new(input, options).items
    new(items)
  elsif parser = Mummy::Constants::Extensions::PARSERS[extension.downcase]
    items = parser.new(input, options).items
    new(items)
  else
    raise "The file isn't of a supported extension - the following are supported: " \
          "#{Mummy::Constants::Extensions::PERMITTED.join(", ")}"
  end
end
new(items) click to toggle source
# File lib/mummy/test.rb, line 22
def initialize(items)
  @items = items
  @starred = []
end

Public Instance Methods

run() click to toggle source
# File lib/mummy/test.rb, line 27
def run
  raise "No items were found - is your file formatted correctly?" unless items.any?

  items.shuffle.each_with_index do |item, index|
    puts "#{index + 1}/#{items.count}. #{item}"
    @starred.push(item) if $stdin.gets.chomp.include?("*")
  end

  run_with_starred if starred.any?
end

Private Instance Methods

run_with_starred() click to toggle source
# File lib/mummy/test.rb, line 42
def run_with_starred
  @items = starred
  @starred = []
  run
end