Module: AnswersHelper

Defined in:
lib/util/answers_helper.rb

Class Method Summary collapse

Class Method Details

.convert_hash_to_answers(answers) ⇒ Object

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



10
11
12
# 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) ⇒ Object

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



17
18
19
20
21
22
23
24
# 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 = {}) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object

=> true, abort: true, overwrite: false => true



5
6
7
# File 'lib/util/answers_helper.rb', line 5

def self.select_symbols(args)
  args.select { |inst, value| inst.is_a?(Symbol) }
end