Class: Block

Block

new Block(_jsonBlock)

The Block object holds other blocks or questions.
Parameters:
Name Type Description
_jsonBlock JSON The json version of the block, passed as the initial input.
Source:

Classes

NEXT_BLOCK

Members

id :string

The user-supplied id. This will have the heirarchical/randomization semantics embedded in it. e.g.: 1._2
Type:
  • string
Source:

idArray :Array.<number>

The idArray allows for quick lookup when comparing different blocks. For example, the block with id 1._2 has an idArray of [1, 2].
Type:
  • Array.<number>
Source:

subblocks :Array.<Block>

The subblocks of this block.
Type:
Source:

topLevelQuestions :Array.<Question>

The questions contained directly in this block, i.e., not in subblocks.
Type:
Source:

Methods

(static) new_block(parent) → {Block}

Add a new block programmatically.
Parameters:
Name Type Description
parent Block | undefined | null If we are creating a subblock, we must supply the parent.
Source:
Returns:
Type
Block

add_block(block, indexnullable)

Adds the block provided block to this block.
Parameters:
Name Type Attributes Description
block Block The block to add.
index number <nullable>
The index at which to add this block.
Source:

add_question(question)

Adds the provided question to this block.
Parameters:
Name Type Description
question Question Question to add to this block.
Source:
Throws:
MalformedSurveyException if the question cannot be added.

equals(that) → {boolean}

Tests whether the supplied item is equivalent, in terms of Block's fields. Note that this is not the same definition of equality that SurveyMan uses for its analyses.
Parameters:
Name Type Description
that * The thing to compare.
Source:
Returns:
Type
boolean

get_parent_id() → {string}

Gets the id of the parent block, to use for parent block lookup.
Source:
Returns:
Type
string

getAllQuestions() → {Array.<Question>}

Returns all questions belonging to this block and its subblocks.
Source:
Returns:
Type
Array.<Question>

getFirstQuestion() → {Question}

Returns the first question to be seen from this block.
Source:
Throws:
MalformedSurveyException if there are no questions or subblocks.
Returns:
Type
Question

getQuestion(quid, deep, thrownotfound) → {Question}

Returns the question object associated with the input id.
Parameters:
Name Type Description
quid string The question's id.
deep boolean Flag indicating whether we should search through subblocks.
thrownotfound boolean Flag indicating whether we should throw an error if the question is not found.
Source:
Throws:
ObjectNotFoundException if this block does not contain a question with the input id at the top level.
Returns:
Type
Question

idComp(that) → {number}

Returns whether that follows (+1), precedes (-1), or is a sub-block (0) of this. If the ids are exactly the same, return 0; this relationship will be symmetric.
Parameters:
Name Type Description
that Block The block to compare.
Source:
Returns:
Type
number

isBranchAll() → {boolean}

Returns boolean indicating whether this is a branch-all block.
Source:
Returns:
Type
boolean

isBranchOne() → {boolean}

Returns boolean indicating whether this is a branch-one block.
Source:
Returns:
Type
boolean

randomize()

Randomizes this block. Shuffles this block's questions and its subblocks appropriately.
Source:

remove_block(block)

Removes the provided block from this block's list of subblocks.
Parameters:
Name Type Description
block
Source:

remove_question(question)

Removes the provided question from this block.
Parameters:
Name Type Description
question The question to remove.
Source:

toJSON() → {Object}

Returns the JSON representation of this block.
Source:
Returns:
Type
Object