Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing to-dict #147

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read(filename):

setup(
name="py-xbrl",
version="2.2.12",
version="2.2.13",
url="https://github.com/manusimidt/xbrl_parser",
license='GNU General Public License v3 (GPLv3)',
author="Manuel Schmidt",
Expand Down
2 changes: 1 addition & 1 deletion xbrl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ContextParseException(InstanceParseException):
pass


__version__ = '2.2.12'
__version__ = '2.2.13'
__author__ = 'Manuel Schmidt <[email protected]>'
__all__ = [
XbrlParseException,
Expand Down
18 changes: 18 additions & 0 deletions xbrl/linkbase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import json
import os
import xml.etree.ElementTree as ET
from abc import ABC
Expand Down Expand Up @@ -247,6 +248,23 @@ def __init__(self, label: str, label_type: str, language: str, text: str) -> Non
# the role of the label i.e: http://www.xbrl.org/2003/role/terseLabel
self.label_type: str = label_type

def to_dict(self):
"""
Converts the Label object into a dictionary representation
"""
return {
'label': self.label,
'label_type': self.label_type,
'language': self.language,
'text': self.text
}

def to_json(self):
"""
Converts the Label object into a JSON string
"""
return json.dumps(self.to_dict(), indent=4)

def __str__(self) -> str:
return self.text

Expand Down
24 changes: 24 additions & 0 deletions xbrl/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import logging
import os
import json
import xml.etree.ElementTree as ET
from functools import lru_cache
from typing import List
Expand Down Expand Up @@ -480,6 +481,29 @@ def __init__(self, xml_id: str, schema_url: str, name: str) -> None:
self.period_type: str or None = None
self.balance: str or None = None
self.labels: [Label] = []

def to_dict(self):
"""
Converts the Concept object into a dictionary representation
"""
return {
'xml_id': self.xml_id,
'schema_url': self.schema_url,
'name': self.name,
'substitution_group': self.substitution_group,
'concept_type': self.concept_type,
'abstract': self.abstract,
'nillable': self.nillable,
'period_type': self.period_type,
'balance': self.balance,
'labels': [label.to_dict() for label in self.labels] if self.labels else [] # Assuming Label class has to_dict()
}

def to_json(self):
"""
Converts the Concept object into a JSON string
"""
return json.dumps(self.to_dict(), indent=4)

def __str__(self) -> str:
return self.name
Expand Down
Loading