Class: Logirel::Queries::BoolQ
- Defined in:
- lib/logirel/queries/bool_q.rb
Instance Attribute Summary collapse
-
#neg_answer ⇒ Object
Returns the value of attribute neg_answer.
-
#pos_answer ⇒ Object
Returns the value of attribute pos_answer.
Attributes inherited from Query
Instance Method Summary collapse
- #default_str ⇒ Object
- #exec ⇒ Object
-
#initialize(question, default = true, io_source = STDIN, io_target = STDOUT) ⇒ BoolQ
constructor
A new instance of BoolQ.
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_answer ⇒ Object
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_answer ⇒ Object
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_str ⇒ Object
18 19 20 21 22 |
# File 'lib/logirel/queries/bool_q.rb', line 18 def default_str @default ? "[Yn]" : "[yN]" end |
#exec ⇒ Object
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 |