kuon.watcher.adapters.models.item   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 96.67%

Importance

Changes 0
Metric Value
wmc 7
eloc 43
dl 0
loc 90
ccs 29
cts 30
cp 0.9667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Item.__init__() 0 31 2
A Item.add_sticker() 0 8 2
A Item.value() 0 18 1
A Item.stickers() 0 8 1
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3 1
from typing import List
4
5 1
from kuon.watcher.adapters.models import AbstractEntity
6 1
from kuon.watcher.adapters.models.sticker import Sticker
7
8
9 1
class Item(AbstractEntity):
10
    """General Item Class"""
11
12 1
    def __init__(self, market_name: str, item_id: str, app_id: int, class_id: int, context_id: int, instance_id: int,
13
                 price: int, wear_value: float, image: str, inspect_link: str, stickers: List[Sticker] = None) -> None:
14
        """Initializing function
15
16
        :type market_name: str
17
        :type item_id: str
18
        :type app_id: int
19
        :type class_id: int
20
        :type context_id: int
21
        :type instance_id: int
22
        :type price: int
23
        :type wear_value: float
24
        :type image: str
25
        :type inspect_link: str
26
        :type stickers: List[Sticker]
27
        """
28 1
        self._market_name = market_name
29 1
        self._item_id = item_id
30 1
        self._app_id = app_id
31 1
        self._class_id = class_id
32 1
        self._context_id = context_id
33 1
        self._instance_id = instance_id
34 1
        self._price = price
35 1
        self._wear_value = wear_value
36 1
        self._image = image
37 1
        self._inspect_link = inspect_link
38
39 1
        if stickers:
40 1
            self._stickers = stickers
41
        else:
42 1
            self._stickers = []
43
44 1
    @property
45 1
    def value(self) -> dict:
46
        """Return all important information from the Steam API
47
48
        :return:
49
        """
50 1
        return {
51
            'market_name': self._market_name,
52
            'item_id': self._item_id,
53
            'app_id': self._app_id,
54
            'class_id': self._class_id,
55
            'context_id': self._context_id,
56
            'instance_id': self._instance_id,
57
            'price': self._price,
58
            'wear_value': self._wear_value,
59
            'image': self._image,
60
            'inspect_link': self._inspect_link,
61
            'stickers': self.stickers
62
        }
63
64 1
    @property
65 1
    def stickers(self) -> list:
66
        """Property for stickers which returns __dict__ of the sticker objects
67
        to allow JSON dump the item without custom JSONEncoder objects
68
69
        :return:
70
        """
71 1
        return [s.__dict__ for s in self._stickers]
72
73 1
    @stickers.setter
74 1
    def stickers(self, stickers: List[Sticker]) -> None:
75
        """Setter for sticker
76
77
        :type stickers: List[Sticker]
78
        :return:
79
        """
80
        self._stickers = stickers
81
82 1
    def add_sticker(self, sticker: Sticker) -> None:
83
        """Adder for sticker
84
85
        :type sticker: Sticker
86
        :return:
87
        """
88 1
        if sticker not in self._stickers:
89
            self._stickers.append(sticker)
90