Class: Consenter

Inherits:
Object
  • Object
show all
Defined in:
lib/consenter.rb,
lib/consenter/version.rb

Overview

:nodoc:

Constant Summary collapse

NAME =
'consenter'.freeze
VERSION =
'1.0.6'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(prompt = '%s', options = {}) ⇒ Consenter

Returns a new instance of Consenter.



30
31
32
33
34
35
36
# File 'lib/consenter.rb', line 30

def initialize(prompt = '%s', options = {})
  @prompt = prompt + ' [' + ANSWERS + '] '

  @inspector  = options.fetch(:inspector, :to_s)
  @no_to_all  = options.fetch(:none, false)
  @yes_to_all = options.fetch(:all, false)
end

Instance Method Details

#for(enumerable, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/consenter.rb', line 66

def for(enumerable, &block)
  enumerable.each do |arg|
    case consent_for? arg
    when true  then block.yield(arg) # user pressed 'y' or 'Y'
    when false then nil              # user pressed 'n' or 'N'
    when nil   then break            # user pressed 'q'
    end
  end
end