Module: ASE::String

Defined in:
lib/as-extensions/ext-logic/string.rb

Class Method Summary collapse

Class Method Details

.from(where) ⇒ Object

Load a string from a file or a URL.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/as-extensions/ext-logic/string.rb', line 24

def from(where)
  where.strip!
  uri = URI.parse(where)
  is_gz = (where.split('.').last == 'gz')
  case uri.scheme
    when nil
      unless File.file?( where = File.expand_path(where) )
        return ASE::log("#{where} is not a file.", :error)
      end
      open(where) do |f| return IO::to_string(f, is_gz) end
    else
      ASE::need 'open-uri'
      args = uri.userinfo ? { :http_basic_authentication => uri.userinfo.split(':') } : {}
      uri.open(args) do |f| return IO::to_string(f, is_gz) end
  end # case
end