Method: URI::Data.build

Defined in:
lib/data_uri/uri.rb

.build(arg) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/data_uri/uri.rb', line 46

def self.build(arg)
  data = nil
  content_type = nil
  case arg
    when IO
      data = arg
    when Hash
      data = arg[:data]
      content_type = arg[:content_type]
  end
  raise 'Invalid build argument: ' + arg.inspect unless data
  if !content_type && data.respond_to?(:content_type)
    content_type = data.content_type
  end
  new('data', nil, nil, nil, nil, nil, "#{content_type};base64,#{Base64.encode64(data.read).chop}", nil, nil)
end