Class: Ora::Cli::Stdin

Inherits:
Object
  • Object
show all
Defined in:
lib/ora/cli/stdin.rb

Instance Method Summary collapse

Constructor Details

#initialize(bash:, print: Print.new, inputs: []) ⇒ Stdin

Returns a new instance of Stdin.



5
6
7
8
9
# File 'lib/ora/cli/stdin.rb', line 5

def initialize(bash:, print: Print.new, inputs: [])
  @bash   = bash
  @print  = print
  @inputs = inputs
end

Instance Method Details

#gets(pattern = '') ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ora/cli/stdin.rb', line 11

def gets(pattern = '')
  input = nil

  until input
    input = @inputs.shift || STDIN.gets.chomp.strip
    unless input.match(pattern)
      @print.red "Please match #{pattern.inspect}"
      input = nil
    end
  end

  input
end

#select(command) ⇒ Object



25
26
27
# File 'lib/ora/cli/stdin.rb', line 25

def select(command)
  @inputs.shift || @bash.select(command)
end