Class: TimerWithSnooze::InputData

Inherits:
Object
  • Object
show all
Defined in:
lib/timer_with_snooze.rb

Class Method Summary collapse

Class Method Details

.input_int_validation(message) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/timer_with_snooze.rb', line 161

def self.input_int_validation(message)
  rooping = true
  while rooping
    print "#{message} : "
    result = gets.chomp!
    if /\d/ === result
      result = result.to_i
      rooping = false
    else
      puts 'Input data is not integer.'
      rooping = true
    end
  end
  result
end

.input_str_validation(message, char) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/timer_with_snooze.rb', line 177

def self.input_str_validation(message, char)
  rooping = true
  while rooping
    print "#{message} : "
    result = gets.chomp!
    if /\D/ === result
        result
        rooping = false
    else
      puts 'Input character was not expected.'
      rooping = true
    end
  end
  result == char
end