#1 Compile class inheriting from `Rule` into a `Rule` trait implementation

Atvērta
unidan atvēra 5 gadi atpakaļ · 0 komentāri
unidan komentēja 5 gadi atpakaļ

Example:

class EpisodeSingleDigitValidator(Rule):
    """
    Remove single digit episode when inside a group that doesn't own title.
    """
    dependency = [TitleFromPosition]

    consequence = RemoveMatch

    def when(self, matches, context):
        ret = []
        for episode in matches.named('episode', lambda match: len(match.initiator) == 1):
            group = matches.markers.at_match(episode, lambda marker: marker.name == 'group', index=0)
            if group:
                if not matches.range(*group.span, predicate=lambda match: match.name == 'title'):
                    ret.append(episode)
        return ret

Should implement something like

trait Rule {
    fn dependencies(&self) -> Vec<Dependency>;
    fn consequence(&self) -> Consequence;
    fn when(&self, matches: Matches, context: Context) -> Vec<Marker>;
}
Example: ``` class EpisodeSingleDigitValidator(Rule): """ Remove single digit episode when inside a group that doesn't own title. """ dependency = [TitleFromPosition] consequence = RemoveMatch def when(self, matches, context): ret = [] for episode in matches.named('episode', lambda match: len(match.initiator) == 1): group = matches.markers.at_match(episode, lambda marker: marker.name == 'group', index=0) if group: if not matches.range(*group.span, predicate=lambda match: match.name == 'title'): ret.append(episode) return ret ``` Should implement something like ``` trait Rule { fn dependencies(&self) -> Vec<Dependency>; fn consequence(&self) -> Consequence; fn when(&self, matches: Matches, context: Context) -> Vec<Marker>; } ```
Pierakstieties, lai pievienotos šai sarunai.
Nav etiķešu
Nav atskaites punktu
Nav atbildīgā
1 dalībnieki
Notiek ielāde...
Atcelt
Saglabāt
Vēl nav satura.