Class: REXML::SourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/compat/opal/rexml/source.rb

Class Method Summary collapse

Class Method Details

.create_from(arg) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/compat/opal/rexml/source.rb', line 37

def SourceFactory::create_from(arg)
  if arg.respond_to? :read and
      arg.respond_to? :readline and
      arg.respond_to? :nil? and
      arg.respond_to? :eof?
    if RUBY_ENGINE == "opal"
      # Opal's StringScanner lacks <<, so use Source (full-string) instead
      # of IOSource (streaming). Read everything upfront.
      Source.new(arg.read, nil)
    else
      IOSource.new(arg)
    end
  elsif arg.respond_to? :to_str
    if RUBY_ENGINE == "opal"
      Source.new(arg, nil)
    else
      IOSource.new(StringIO.new(arg))
    end
  elsif arg.kind_of? Source
    arg
  else
    raise "#{arg.class} is not a valid input stream.  It must walk \n"+
      "like either a String, an IO, or a Source."
  end
end