Note: This is an Unofficial Community Project
API Reference¶
API¶
Course¶
-
class
api.course.Course(author, course, chapters, path, **kwargs)¶ -
__init__(author, course, chapters, path, **kwargs)¶ Creates a new Course object, that parses details from a course.yaml file.
- Parameters
author (str) – The name of the author(s) who created the course.
course (str) – The name of the course, it should ideally be descriptive. (ex. “Hub Datasets”)
chapters (str) – The names of the chapters separated by semi-colons (;), the delimiter is important.
path (str) – The directory path where the course.yaml file is located.
description (str, optional) – A short and precise description of the course.
organization (str, optional) – The organization the author belongs to. Could be None if no affiliation is to be shown.
-
__weakref__¶ list of weak references to the object (if defined)
-
contents()¶ Lists the chapters in the course in an indexed manner.
-
describe()¶ Prints the - Name of the Course - Name of the Author(s) - Description of the Course (if available)
-
classmethod
load(path)¶ A class method responsible for loading the Course from the course.yaml file into an object of the Class.
- Parameters
path (str) – The directory path where the course.yaml file can be found.
-
load_chapter(chapter_id)¶ Takes the user’s chapter selection and verifies if it is a proper selection. Then loads the chapter.yaml file into memory and return the Chapter object.
- Parameters
chapter_id (int) – The index of the chapter selected by the user (Indexes starting from 1).
-
serve()¶ Gives the user the contents of the course and asks the user to select a chapteṛ.
-
serve_chapter(chapter_id)¶ Takes the user’s chapter selection and loads the chapter into memory. Then proceeds to serve the chapter.
- Parameters
chapter_id (int) – The index of the chapter selected by the user (Indexes starting from 1).
-
slugify(text)¶ Converts normal text to file name approved slugs, by removing forbidden characters and replacing spaces with “-“.
- Parameters
text (str) – The normal text that needs to be converted into a slug.
-
verify()¶ Checks if the Course has atleast some value for the essential fields. Then checks if each Chapter has a verification test, if yes, then the test is carried out.
-
Chapter¶
-
class
api.chapter.Chapter(snippets)¶ -
__init__(snippets)¶ Creates a Chapter object containing all the relevant snippets.
- Parameters
snippets (List) – List of Snippets contained in the chapter.yaml file.
-
__weakref__¶ list of weak references to the object (if defined)
-
classmethod
load(file)¶ Class Method. Loads a Chapter from an already opened file. Also forwards the file to initialize all the Snippets.
- Parameters
file (file) – Already opened .yaml file that contains details of Snippets in the chapter.
-
serve(initial_data={})¶ Iterates over each snippet and serves it on the console.
-
verify()¶ Verifies the Snippet if it has a test available.
-
Snippet¶
-
class
api.snippet.Snippet(category, prompt, **kwargs)¶ -
__init__(category, prompt, **kwargs)¶ Base Class for all the types of Snippets. Creates a Base Snippet Object. Then changes the class of the object to its specific sub-class.
- Parameters
category (str) – Type of Snippet, this name will be used to assign the object its specific sub-class. (ex. “Text”, “MCQ”)
prompt (str) – The input prompt that will be displayed on the console before the user input for this snippet is taken.
-
__metaclass__¶ alias of
abc.ABCMeta
-
__weakref__¶ list of weak references to the object (if defined)
-
check_required(fields)¶ Checks if there exists atleast some value for the required fields of the specific snippet.
- Parameters
fields (List) – List of fields that will be checked in the object.
-
abstract
get_response(data={})¶ Abstract Method. To be implemented in every Sub-Class that inherits from this as a base class. Describes the kind of input and the method of getting that input.
-
classmethod
load(file)¶ Class Method. Reads a .yaml` file and initializes all the Snippet objects from that file.
- Parameters
file (file) – Already opened .yaml file that contains information about the snippets in the chapter.
-
print_prompt()¶ Prints the prompt of the Snippet.
-
serve(data={})¶ Serves the Snippet by printing the prompt, taking user input and testing it.
-
abstract
test_response(response, data={})¶ Abstract Method. To be implemented in every Sub-Class that inherits from this as a base class. Describes the method of testing the user input for correctness.
-
Non-Console Snippet¶
-
class
api.snippet.NonConsoleSnippet(category, prompt, **kwargs)¶ -
__init__(category, prompt, **kwargs)¶ Initializes a Snippet Object that does not require an Interactive Console.
- Parameters
category (str) – Type of Snippet, this name will be used to assign the object its specific sub-class. (ex. “Text”, “MCQ”)
prompt (str) – The input prompt that will be displayed on the console before the user input for this snippet is taken.
-
__metaclass__¶ alias of
abc.ABCMeta
-
Snippets¶
Text Snippet¶
-
class
api.snippets.textSnippet.textSnippet(category, prompt, **kwargs)¶ -
get_response(data={})¶ Takes in a key press as user input.
-
test_response(response, data={})¶ Abstract Method. To be implemented in every Sub-Class that inherits from this as a base class. Describes the method of testing the user input for correctness.
-
verify()¶ Verifies if Snippet prompt is a string.
-
MCQ Snippet¶
-
class
api.snippets.mcqSnippet.mcqSnippet(category, prompt, **kwargs)¶ -
get_response(data={})¶ Fetches an option from the user and checks if it is a valud option.
-
test_response(response, data={})¶ Tests if the user’s answer is the correct answer.
-
verify()¶ Checks if the correct answer is present as an option.
-