module AnswersHelper

Public Class Methods

convert_hash_to_answers(answers) click to toggle source

{abort: true} => [Answer.new(:abort => true)]

# File lib/util/answers_helper.rb, line 10
def self.convert_hash_to_answers(answers)
  answers.reduce([]) { |array, (inst, value)| array << Answer.new({inst => value}) }
end
convert_symbol_to_answer_or_send_through(arg) click to toggle source

:symbol => Answer.new(:symbol) Answer.new(:symbol) => Answer.new(:symbol) “string” => raise ArgumentError

# File lib/util/answers_helper.rb, line 17
def self.convert_symbol_to_answer_or_send_through(arg)
  case arg
  when Answer then arg
  when Symbol then Answer.new(arg)
  else
    raise ArgumentError
  end
end
free_indicator_of(answer, opts={}) click to toggle source

Gets first free indicator for ‘answer` which isn’t used by ‘used_indicators`.

# File lib/util/answers_helper.rb, line 27
def self.free_indicator_of answer, opts={}
  opts = {:used_indicators => []}.merge(opts)
  used_indicators = opts[:used_indicators]

  first_chars = 1
  loop do
    indicator = answer.indicator(first_chars)
    if used_indicators.include? indicator
      first_chars += 1
      redo # next try
    else
      return indicator
    end
  end
end
select_symbols(args) click to toggle source

{“abc” => true, abort: true, overwrite: false} => {abort: true}

# File lib/util/answers_helper.rb, line 5
def self.select_symbols(args)
  args.select { |inst, value| inst.is_a?(Symbol) }
end