Class: IOHelper

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

Overview

© 2024 Gerald Hilts License: MIT (github.com/gwhilts/cve_lookup/blob/main/LICENSE)

Instance Method Summary collapse

Constructor Details

#initialize(test_mode = false) ⇒ IOHelper

Returns a new instance of IOHelper.



7
8
9
# File 'lib/io_helper.rb', line 7

def initialize(test_mode = false)
  @test = test_mode
end

Instance Method Details

#request(prompt, test_val = "TEST") ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/io_helper.rb', line 11

def request(prompt, test_val = "TEST")
  unless @test
    print "#{prompt} "
    $stdin.gets.chomp
  else
    test_val
  end
end

#request_from_range(range, test_val = 0) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/io_helper.rb', line 20

def request_from_range(range, test_val = 0)
  unless @test
    response = ""
    until (response.match /^(\d+|X)/) && (range.include? response.to_i) do
      response = request("#{range.first} - #{range.last}: ")
    end
    response
  else
    test_val
  end
end