# mypy: allow-untyped-defs

from ._abstract import AbstractScraper


class RutgerBakt(AbstractScraper):
    @classmethod
    def host(cls):
        return "rutgerbakt.nl"

    def author(self):
        return "Rutger van den Broek"

    def title(self):
        title_raw = self.schema.title()
        return title_raw.replace(" – recept", "").replace(" – Recept", "")

    def category(self):
        category = (
            self.url.split("rutgerbakt.nl/")[-1]
            .split("/")[0]
            .replace("-recepten", "")
            .replace("-", " ")
        )
        return category

    def total_time(self):
        return self.schema.total_time()

    def yields(self):
        # The yields are all over the place. There is no way to parse this.
        return None

    def image(self):
        return self.schema.image()

    def ingredients(self):
        return self.schema.ingredients()

    def instructions(self):
        # Find the "instructions" heading. It is not really clear when that is.
        # So several steps need to be taken.

        # 1. Filter all the headings.
        # Some h2 headers contain photos. Those are not what we want.
        def filter_heading(headings_old):
            headings_new = []
            for _heading in headings_old:
                if "class" in _heading.attrs:
                    h_class = _heading.attrs["class"]
                    if any("photo" in attr.lower() for attr in h_class):
                        continue
                headings_new.append(_heading)
            return headings_new

        headings = filter_heading(self.soup.find_all("h2"))

        # 2. Find the instructions heading
        # Usually the last heading are the instructions
        # (therefore headings.reverse()).
        # But it's double checked whether the heading contains any of
        # the keywords.
        # I split the heading into words so I keep word boundaries in check.
        headings.reverse()
        for heading in headings:
            tokens = heading.getText().lower().split(" ")
            keywords = ["recept", "bereiding", "maken", "maak"]
            if any(keyword in tokens for keyword in keywords):
                break

        # This function iterates over every next element after the heading.
        def parse_instructions(element):
            for instruction in element.next_siblings:
                if instruction.name not in ["p", "h2", "h3", "h4"]:
                    continue
                if any(
                    item in instruction.text.lower()
                    for item in ["foto: ", "foto's: ", "foto’s: "]
                ):
                    continue
                yield instruction.text.replace("\n", " ").strip()

        instructions = parse_instructions(heading)
        return "\n".join(instructions)

    def ratings(self):
        return self.schema.ratings()

    def description(self):
        # Assuming the first paragraph is the description.
        return self.soup.find("p").text.replace("\n", " ")

62c5f83022d1bad95d9ea535795e04b420b95f55
<mask token>


class RutgerBakt(AbstractScraper):

    @classmethod
    def host(cls):
        return 'rutgerbakt.nl'
    <mask token>
    <mask token>
    <mask token>

    def total_time(self):
        return self.schema.total_time()
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def ratings(self):
        return self.schema.ratings()
    <mask token>

<mask token>


class RutgerBakt(AbstractScraper):

    @classmethod
    def host(cls):
        return 'rutgerbakt.nl'

    def author(self):
        return 'Rutger van den Broek'

    def title(self):
        title_raw = self.schema.title()
        return title_raw.replace(' – recept', '').replace(' – Recept', '')
    <mask token>

    def total_time(self):
        return self.schema.total_time()

    def yields(self):
        return None

    def image(self):
        return self.schema.image()
    <mask token>
    <mask token>

    def ratings(self):
        return self.schema.ratings()

    def description(self):
        return self.soup.find('p').text.replace('\n', ' ')

<mask token>


class RutgerBakt(AbstractScraper):

    @classmethod
    def host(cls):
        return 'rutgerbakt.nl'

    def author(self):
        return 'Rutger van den Broek'

    def title(self):
        title_raw = self.schema.title()
        return title_raw.replace(' – recept', '').replace(' – Recept', '')

    def category(self):
        category = self.url.split('rutgerbakt.nl/')[-1].split('/')[0].replace(
            '-recepten', '').replace('-', ' ')
        return category

    def total_time(self):
        return self.schema.total_time()

    def yields(self):
        return None

    def image(self):
        return self.schema.image()

    def ingredients(self):
        return self.schema.ingredients()
    <mask token>

    def ratings(self):
        return self.schema.ratings()

    def description(self):
        return self.soup.find('p').text.replace('\n', ' ')

<mask token>


class RutgerBakt(AbstractScraper):

    @classmethod
    def host(cls):
        return 'rutgerbakt.nl'

    def author(self):
        return 'Rutger van den Broek'

    def title(self):
        title_raw = self.schema.title()
        return title_raw.replace(' – recept', '').replace(' – Recept', '')

    def category(self):
        category = self.url.split('rutgerbakt.nl/')[-1].split('/')[0].replace(
            '-recepten', '').replace('-', ' ')
        return category

    def total_time(self):
        return self.schema.total_time()

    def yields(self):
        return None

    def image(self):
        return self.schema.image()

    def ingredients(self):
        return self.schema.ingredients()

    def instructions(self):

        def filter_heading(headings_old):
            headings_new = []
            for _heading in headings_old:
                if 'class' in _heading.attrs:
                    h_class = _heading.attrs['class']
                    if any('photo' in attr.lower() for attr in h_class):
                        continue
                headings_new.append(_heading)
            return headings_new
        headings = filter_heading(self.soup.find_all('h2'))
        headings.reverse()
        for heading in headings:
            tokens = heading.getText().lower().split(' ')
            keywords = ['recept', 'bereiding', 'maken', 'maak']
            if any(keyword in tokens for keyword in keywords):
                break

        def parse_instructions(element):
            for instruction in element.next_siblings:
                if instruction.name not in ['p', 'h2', 'h3', 'h4']:
                    continue
                if any(item in instruction.text.lower() for item in [
                    'foto: ', "foto's: ", 'foto’s: ']):
                    continue
                yield instruction.text.replace('\n', ' ').strip()
        instructions = parse_instructions(heading)
        return '\n'.join(instructions)

    def ratings(self):
        return self.schema.ratings()

    def description(self):
        return self.soup.find('p').text.replace('\n', ' ')

# mypy: allow-untyped-defs

from ._abstract import AbstractScraper


class RutgerBakt(AbstractScraper):
    @classmethod
    def host(cls):
        return "rutgerbakt.nl"

    def author(self):
        return "Rutger van den Broek"

    def title(self):
        title_raw = self.schema.title()
        return title_raw.replace(" – recept", "").replace(" – Recept", "")

    def category(self):
        category = (
            self.url.split("rutgerbakt.nl/")[-1]
            .split("/")[0]
            .replace("-recepten", "")
            .replace("-", " ")
        )
        return category

    def total_time(self):
        return self.schema.total_time()

    def yields(self):
        # The yields are all over the place. There is no way to parse this.
        return None

    def image(self):
        return self.schema.image()

    def ingredients(self):
        return self.schema.ingredients()

    def instructions(self):
        # Find the "instructions" heading. It is not really clear when that is.
        # So several steps need to be taken.

        # 1. Filter all the headings.
        # Some h2 headers contain photos. Those are not what we want.
        def filter_heading(headings_old):
            headings_new = []
            for _heading in headings_old:
                if "class" in _heading.attrs:
                    h_class = _heading.attrs["class"]
                    if any("photo" in attr.lower() for attr in h_class):
                        continue
                headings_new.append(_heading)
            return headings_new

        headings = filter_heading(self.soup.find_all("h2"))

        # 2. Find the instructions heading
        # Usually the last heading are the instructions
        # (therefore headings.reverse()).
        # But it's double checked whether the heading contains any of
        # the keywords.
        # I split the heading into words so I keep word boundaries in check.
        headings.reverse()
        for heading in headings:
            tokens = heading.getText().lower().split(" ")
            keywords = ["recept", "bereiding", "maken", "maak"]
            if any(keyword in tokens for keyword in keywords):
                break

        # This function iterates over every next element after the heading.
        def parse_instructions(element):
            for instruction in element.next_siblings:
                if instruction.name not in ["p", "h2", "h3", "h4"]:
                    continue
                if any(
                    item in instruction.text.lower()
                    for item in ["foto: ", "foto's: ", "foto’s: "]
                ):
                    continue
                yield instruction.text.replace("\n", " ").strip()

        instructions = parse_instructions(heading)
        return "\n".join(instructions)

    def ratings(self):
        return self.schema.ratings()

    def description(self):
        # Assuming the first paragraph is the description.
        return self.soup.find("p").text.replace("\n", " ")
