Class: JupyterNB::Cell

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/cell.rb

Instance Method Summary collapse

Methods included from Helpers

#add_field, #add_string, #close_array, #close_group, #open_array, #open_group

Constructor Details

#initialize(type, metadata, outputs, source) ⇒ Cell

Constructor

Parameters:

  • type (String)

    defines the type of the cell (markdown, code, …)

  • metadata

    can be given as a string with linebreaks or as an array of strings

  • outputs

    can be given as a string with linebreaks or as an array of strings def add_cell(type,metadata,outputs,source)

  • source

    can be given as a string with linebreaks or as an array of strings



31
32
33
34
35
36
# File 'lib/cell.rb', line 31

def initialize(type, , outputs, source)
  @type = type
   = read_parameter()
  @source = read_parameter(source)
  @count = 0
end

Instance Method Details

#generate(indent = 1, last = false) ⇒ Object

Returns a string that contains an IPython Notebook cell

The outputs field is not implemented yet. Should actually not be necessary for a pure generator. Generation of metadata within the cell is also not yet implemented.

Parameters:

  • indent (Integer) (defaults to: 1)

    defines the indentation of the cell content

  • last (Boolean) (defaults to: false)

    if set to true, the trailing ‘,’ is omitted



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cell.rb', line 46

def generate(indent=1,last=false)
  @indent = indent

  result = ""
  result << open_group
  result << add_field("cell_type", @type)
  result << add_field("execution_count", @count) if (@type == "code")
  result << open_group("metadata")
  # not implemented yet
  result << close_group

  result << open_array("source")

  @source.each do |l|
    result << add_string(l)

    (l.equal? @source.last) ? result << "\n" : result << ",\n"
  end
  result << close_array(true)
  result << close_group(last)

  return result
end