1"""
2    pyexcel.plugins.sources.pydata.arraysource
3    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5    Representation of array source
6
7    :copyright: (c) 2015-2020 by Onni Software Ltd.
8    :license: New BSD License
9"""
10from pyexcel.source import AbstractSource, MemorySourceMixin
11from pyexcel.constants import DEFAULT_SHEET_NAME
12from pyexcel.plugins.sources import params
13
14from .common import ArrayReader, _FakeIO
15
16
17class ArraySource(AbstractSource, MemorySourceMixin):
18    """
19    A two dimensional array as sheet source
20    """
21
22    def __init__(self, array, sheet_name=DEFAULT_SHEET_NAME, **keywords):
23        self.__array = array
24        self._content = _FakeIO()
25        self.__sheet_name = sheet_name
26        AbstractSource.__init__(self, **keywords)
27
28    def get_data(self):
29        array_reader = ArrayReader(self.__array, **self._keywords)
30        return {self.__sheet_name: array_reader.to_array()}
31
32    def get_source_info(self):
33        return params.ARRAY, None
34
35    def write_data(self, sheet):
36        self._content.setvalue(sheet.to_array())
37