Class: JupyterNB::Generator
- Inherits:
-
Object
- Object
- JupyterNB::Generator
- Includes:
- Helpers
- Defined in:
- lib/generator.rb
Instance Method Summary collapse
-
#add_cell(type, metadata, outputs, source) ⇒ Object
Adds a content cell to the notebook to be generated.
-
#generate ⇒ Object
Returns a string that contains an IPython Notebook.
-
#initialize(lang) ⇒ Generator
constructor
Default constructor.
Methods included from Helpers
#add_field, #add_string, #close_array, #close_group, #open_array, #open_group
Constructor Details
#initialize(lang) ⇒ Generator
Default constructor
22 23 24 25 26 27 28 |
# File 'lib/generator.rb', line 22 def initialize(lang) @cells = Array.new if ((lang == :ruby) or (lang == :python3) or (lang == :julia)) = Metadata.new(lang) end end |
Instance Method Details
#add_cell(type, metadata, outputs, source) ⇒ Object
Adds a content cell to the notebook to be generated
63 64 65 |
# File 'lib/generator.rb', line 63 def add_cell(type,,outputs,source) @cells << Cell.new(type,,outputs,source) end |
#generate ⇒ Object
Returns a string that contains an IPython Notebook
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generator.rb', line 31 def generate # start with 1 because everything is encapsulated within {} # at indent 0 @indent = 1 result = "" result << "{\n" if (@cells.nil? == false) and (@cells.size > 0) result << open_array("cells") @cells.each do |c| last = false (c == @cells.last) ? last = true : last = false result << c.generate(@indent, last) end result << close_array end result << result << generate_versioninfo result << "}" return result end |