From 492795f1a2f00fc75e82fbadfc06e5e6c6e51c0a Mon Sep 17 00:00:00 2001 From: p_monsalvete Date: Tue, 25 Apr 2023 11:48:24 -0400 Subject: [PATCH] added new functions to access chapter and item by name in costs catalog --- hub/catalog_factories/data_models/cost/capital_cost.py | 10 ++++++++++ hub/catalog_factories/data_models/cost/chapter.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/hub/catalog_factories/data_models/cost/capital_cost.py b/hub/catalog_factories/data_models/cost/capital_cost.py index 828b5cfc..94981e42 100644 --- a/hub/catalog_factories/data_models/cost/capital_cost.py +++ b/hub/catalog_factories/data_models/cost/capital_cost.py @@ -38,3 +38,13 @@ class CapitalCost: :return: float """ return self._overhead_and_profit + + def chapter(self, name) -> Chapter: + """ + Get specific chapter by name + :return: Chapter + """ + for chapter in self.general_chapters: + if chapter.chapter_type == name: + return chapter + raise KeyError(f'Chapter name {name} not found') diff --git a/hub/catalog_factories/data_models/cost/chapter.py b/hub/catalog_factories/data_models/cost/chapter.py index bf393cbb..2cd7b4e6 100644 --- a/hub/catalog_factories/data_models/cost/chapter.py +++ b/hub/catalog_factories/data_models/cost/chapter.py @@ -30,3 +30,13 @@ class Chapter: :return: [str] """ return self._items + + def item(self, name) -> ItemDescription: + """ + Get specific item by name + :return: ItemDescription + """ + for item in self.items: + if item.type == name: + return item + raise KeyError(f'Item name {name} not found')