Product or Sector Specific Rule
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
pact_methodology
project code.
ProductOrSectorSpecificRule
Represents a product or sector specific rule for calculating carbon footprints.
This class represents rules and methodologies published by specific operators that must be followed when calculating product carbon footprints. These rules can come from various sources like PEF (Product Environmental Footprint) or custom operators.
Attributes:
Name | Type | Description |
---|---|---|
operator |
ProductOrSectorSpecificRuleOperator
|
The operator that published the specific rule. Must be a valid ProductOrSectorSpecificRuleOperator enum value. |
rule_names |
list[str]
|
A list of names of the rules applied from the specified operator. Each rule name must be a string. |
other_operator_name |
str | None
|
The name of the operator if the operator is 'Other'. Required when operator is ProductOrSectorSpecificRuleOperator.OTHER, must be None otherwise. |
Examples:
Create a rule for PEF methodology:
>>> rule = ProductOrSectorSpecificRule(
... operator=ProductOrSectorSpecificRuleOperator.PEF,
... rule_names=["PEFCR Guidance v6.3"]
... )
Create a rule with a custom operator:
>>> custom_rule = ProductOrSectorSpecificRule(
... operator=ProductOrSectorSpecificRuleOperator.OTHER,
... rule_names=["Custom Rule 1", "Custom Rule 2"],
... other_operator_name="My Organization"
... )
Convert rule to dictionary format:
>>> rule.to_dict()
{'operator': 'PEF', 'ruleNames': ['PEFCR Guidance v6.3']}
Raises:
Type | Description |
---|---|
ValueError
|
If operator is not a valid ProductOrSectorSpecificRuleOperator, if rule_names is not a list of strings, or if other_operator_name is provided incorrectly based on the operator value. |
TypeError
|
If required arguments are missing during initialization. |
Note
The other_operator_name is only valid and required when operator is set to ProductOrSectorSpecificRuleOperator.OTHER. For all other operators, it must be None.
Source code in pact_methodology/carbon_footprint/product_or_sector_specific_rule.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
operator
property
writable
Get the rule operator.
Returns:
Type | Description |
---|---|
ProductOrSectorSpecificRuleOperator
|
The ProductOrSectorSpecificRuleOperator enum value |
other_operator_name
property
writable
Get the custom operator name if operator is "Other".
Returns:
Type | Description |
---|---|
str | None
|
The custom operator name string or None |
rule_names
property
writable
Get the list of rule names.
Returns:
Type | Description |
---|---|
list[str]
|
List of rule name strings |
__init__(operator, rule_names, other_operator_name=None)
Initialize a ProductOrSectorSpecificRule instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
ProductOrSectorSpecificRuleOperator
|
The operator publishing the rule (e.g. PEF, GHG Protocol) |
required |
rule_names
|
list[str]
|
List of specific rule names from the operator |
required |
other_operator_name
|
str | None
|
Name of custom operator if operator is "Other" |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If arguments are invalid |
TypeError
|
If required arguments are missing |
Source code in pact_methodology/carbon_footprint/product_or_sector_specific_rule.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
__repr__()
Get detailed string representation of the rule.
Returns:
Type | Description |
---|---|
str
|
A string that could be used to recreate the object |
Source code in pact_methodology/carbon_footprint/product_or_sector_specific_rule.py
173 174 175 176 177 178 179 180 181 182 |
|
__str__()
Get string representation of the rule.
Returns:
Type | Description |
---|---|
str
|
A human-readable string showing the rule's attributes |
Source code in pact_methodology/carbon_footprint/product_or_sector_specific_rule.py
163 164 165 166 167 168 169 170 171 |
|
to_dict()
Convert the rule to a dictionary representation.
Returns:
Type | Description |
---|---|
dict
|
A dictionary with the following structure: |
dict
|
{ "operator": str, # The operator value "rule_names": list[str], # List of rule names "other_operator_name": str | None # Custom operator name if applicable |
dict
|
} |
Source code in pact_methodology/carbon_footprint/product_or_sector_specific_rule.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|