Class: TinyClassifier::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny-classifier/input.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Input

Returns a new instance of Input.



18
19
20
# File 'lib/tiny-classifier/input.rb', line 18

def initialize(data = nil)
  @data = data
end

Instance Method Details

#given?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/tiny-classifier/input.rb', line 22

def given?
  return true if @data or $stdin.is_a?(StringIO)
  File.pipe?(STDIN)
end

#readObject



27
28
29
# File 'lib/tiny-classifier/input.rb', line 27

def read
  @data ||= $stdin.readlines.join(" ").strip
end