6.5. Has

6.5.1. Has

class easydata.parsers.has.Has(*args, contains: Optional[Union[list, str]] = None, ccontains: Optional[Union[list, str]] = None, contains_query: Optional[easydata.queries.base.QuerySearchBase] = None, has_value: bool = False, empty_as_false: bool = True, **kwargs)[source]

Bases: easydata.parsers.text.Text

Getting Started

Has supports any query object for fetching data.

>>> ed.Has(ed.jp('info.stock')).parse({'info': {'stock': True}})
True

In this case if jp returns None, then bool parser will also return False.

>>> ed.Has(ed.jp('invalid-key')).parse({})
False

Use of query selectors is not required, as we can see bellow.

>>> ed.Bool().parse(True)
True

Parameters

contains

contains property can accept list of keys which will be used for a match in a lookup text. If match is found then True is returned. Please note that search keys are not case sensitive and regex pattern as a key is also accepted.

>>> ed.Has(contains=['pro 13']).parse('Easybook Pro 13')
True
ccontains

ccontains works in a same way as contains parameter, with an exception that keys are case sensitive.

>>> ed.Has(contains=['Pro 13']).parse('Easybook Pro 13')
True

Lets try with lowercase keys.

>>> ed.Has(contains=['Pro 13']).parse('Easybook Pro 13')
False
contains_query

contains_query is a powerful feature that enables you to specify dynamic search keys by using query selectors. In example bellow we will use jp query selector to get our contains keys.

>>> test_dict = {'title': 'Easybook Pro 13', 'info': {'brand': 'Easybook}'}}
>>> ed.Has(ed.jp('title'), contains_query=ed.jp('info.brand')).parse(test_dict)
True

6.5.2. IHas

class easydata.parsers.has.IHas(*args, contains: Optional[Union[list, str]] = None, ccontains: Optional[Union[list, str]] = None, contains_query: Optional[easydata.queries.base.QuerySearchBase] = None, has_value: bool = False, empty_as_false: bool = True, **kwargs)[source]

Bases: easydata.parsers.has.Has

examples coming soon …

6.5.3. Bool

class easydata.parsers.has.Bool(query: Optional[Union[easydata.queries.base.QuerySearchBase, easydata.parsers.base.BaseData]] = None, from_item: Optional[str] = None, default: Optional[Any] = None, default_from_item: Optional[str] = None, source: Optional[str] = None, process_raw_value: Optional[Union[Callable, easydata.parsers.base.Base]] = None, process_value: Optional[Union[Callable, easydata.parsers.base.Base]] = None, empty_as_none: bool = False, debug: bool = False, debug_source: bool = False)[source]

Bases: easydata.parsers.base.BaseData

examples coming soon …

6.5.4. IBool

class easydata.parsers.has.IBool(query: Optional[Union[easydata.queries.base.QuerySearchBase, easydata.parsers.base.BaseData]] = None, from_item: Optional[str] = None, default: Optional[Any] = None, default_from_item: Optional[str] = None, source: Optional[str] = None, process_raw_value: Optional[Union[Callable, easydata.parsers.base.Base]] = None, process_value: Optional[Union[Callable, easydata.parsers.base.Base]] = None, empty_as_none: bool = False, debug: bool = False, debug_source: bool = False)[source]

Bases: easydata.parsers.has.Bool

examples coming soon …