FormatFactory.create()   C
last analyzed

Complexity

Conditions 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
c 0
b 0
f 0
dl 0
loc 16
rs 6.6666
1
from niprov.dependencies import Dependencies
2
from niprov.formatjson import JsonFormat
3
from niprov.formatxml import XmlFormat
4
from niprov.formatnarrated import NarratedFormat
5
from niprov.formatsimple import SimpleFormat
6
from niprov.formatdict import DictFormat
7
from niprov.formatobject import ObjectFormat
8
from niprov.pictures import PictureCache
9
10
11
class FormatFactory(object):
12
13
    def __init__(self, dependencies=Dependencies()):
14
        self.dependencies = dependencies
15
16
    def create(self, formatName):
17
        if formatName == 'json':
18
            return JsonFormat(self.dependencies)
19
        if formatName == 'xml':
20
            return XmlFormat(self.dependencies)
21
        if formatName == 'narrated':
22
            return NarratedFormat()
23
        if formatName == 'simple':
24
            return SimpleFormat()
25
        if formatName == 'dict':
26
            return DictFormat()
27
        if formatName == 'object':
28
            return ObjectFormat()
29
        if formatName == 'picture':
30
            return PictureCache(self.dependencies)
31
        raise ValueError('Unknown format: '+str(formatName))
32