Module: IRuby::Display

Defined in:
lib/iruby/display.rb

Defined Under Namespace

Modules: Registry Classes: Renderer, Representation

Class Method Summary collapse

Class Method Details

.clear_output(wait = false) ⇒ Object



35
36
37
# File 'lib/iruby/display.rb', line 35

def clear_output(wait=false)
  IRuby::Kernel.instance.session.send(:publish, :clear_output, {wait: wait})
end

.convert(obj, options) ⇒ Object



4
5
6
# File 'lib/iruby/display.rb', line 4

def convert(obj, options)
  Representation.new(obj, options)
end

.display(obj, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/iruby/display.rb', line 8

def display(obj, options = {})
  obj = convert(obj, options)
  options = obj.options
  obj = obj.object

  fuzzy_mime = options[:format] # Treated like a fuzzy mime type
  raise 'Invalid argument :format' unless !fuzzy_mime || String === fuzzy_mime
  if exact_mime = options[:mime]
    raise 'Invalid argument :mime' unless String === exact_mime
    raise 'Invalid mime type' unless exact_mime.include?('/')
  end

  data = {}

  # Render additional representation
  render(data, obj, exact_mime, fuzzy_mime)

  # IPython always requires a text representation
  render(data, obj, 'text/plain', nil) unless data['text/plain']

  # As a last resort, interpret string representation of the object
  # as the given mime type.
  data[exact_mime] = protect(exact_mime, obj) if exact_mime && !data.any? {|m,_| exact_mime == m }

  data
end