class FlatKit::Input::IO

Constants

STDINS

Public Class Methods

handles?(obj) click to toggle source
# File lib/flat_kit/input/io.rb, line 6
def self.handles?(obj)
  return true if is_stdin?(obj)
  return true if [ ::File, ::StringIO, ::IO ].any? { |klass| obj.kind_of?(klass) }
  return false
end
is_stdin?(obj) click to toggle source
# File lib/flat_kit/input/io.rb, line 12
def self.is_stdin?(obj)
  case obj
  when String
    return true if STDINS.include?(obj)
  when ::IO
    return true if obj == ::STDIN
  end
  return false
end
new(obj) click to toggle source
# File lib/flat_kit/input/io.rb, line 22
def initialize(obj)
  if self.class.is_stdin?(obj) then
    @name = "<STDIN>"
    @io = $stdin
  elsif obj.kind_of?(::File) then
    @name = obj.path
    @io = obj
  elsif obj.kind_of?(::StringIO) then
    @name = obj.inspect
    @io = obj
  elsif obj.kind_of?(::IO) then
    @name = obj.inspect
    @io = obj
  else
    raise ::FlatKit::Error, "Unable to create #{self.class} from #{obj.class} : #{obj.inspect}"
  end
end

Public Instance Methods

close() click to toggle source

this goes to an io stream and we are not in charge of opening it

# File lib/flat_kit/input/io.rb, line 45
def close
  @io.close
end
io() click to toggle source
# File lib/flat_kit/input/io.rb, line 49
def io
  @io
end
name() click to toggle source
# File lib/flat_kit/input/io.rb, line 40
def name
  @name
end