Class: Logirel::Queries::BoolQ

Inherits:
Query
  • Object
show all
Defined in:
lib/logirel/queries/bool_q.rb

Instance Attribute Summary collapse

Attributes inherited from Query

#default, #question

Instance Method Summary collapse

Constructor Details

#initialize(question, default = true, io_source = STDIN, io_target = STDOUT) ⇒ BoolQ

Returns a new instance of BoolQ.



8
9
10
11
12
13
14
15
16
# File 'lib/logirel/queries/bool_q.rb', line 8

def initialize(question,
    default = true,
    io_source = STDIN,
    io_target = STDOUT)
  @question = question
  @default = default
  @io_source = io_source
  @io_target = io_target
end

Instance Attribute Details

#neg_answerObject

Returns the value of attribute neg_answer.



6
7
8
# File 'lib/logirel/queries/bool_q.rb', line 6

def neg_answer
  @neg_answer
end

#pos_answerObject

Returns the value of attribute pos_answer.



6
7
8
# File 'lib/logirel/queries/bool_q.rb', line 6

def pos_answer
  @pos_answer
end

Instance Method Details

#default_strObject



18
19
20
21
22
# File 'lib/logirel/queries/bool_q.rb', line 18

def default_str

  @default ? "[Yn]" : "[yN]"

end

#execObject



24
25
26
27
28
29
30
31
# File 'lib/logirel/queries/bool_q.rb', line 24

def exec
  @io_target.print @question + " " + default_str
  a = ""
  begin
    a = @io_source.gets.chomp
  end while !a.empty? && !['y', 'n'].include?(a.downcase)
  a.empty? ? @default : (a == 'y')
end