addBlockAtDepth method

CrawledBlock addBlockAtDepth(
  1. CrawledBlock block,
  2. int depth
)

Implementation

CrawledBlock addBlockAtDepth(CrawledBlock block, int depth) {
  assert(depth >= 0);
  assert(depth == 0 || nestedBlocks.isNotEmpty);
  if (depth == 0) {
    return copyWith(
      nestedBlocks: [...nestedBlocks, block],
    );
  }
  return copyWith(
    nestedBlocks: [
      ...(nestedBlocks.length > 1
          ? nestedBlocks.sublist(0, nestedBlocks.length - 1)
          : []),
      nestedBlocks.last.addBlockAtDepth(block, depth - 1),
    ],
  );
}