addPropertyAtDepth method

CrawledBlock addPropertyAtDepth(
  1. CrawledProperty property,
  2. int depth
)

Implementation

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