|
| 1 | +module Docs |
| 2 | + class Polars |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + # Map the leading path segment of a reference page to a human readable |
| 5 | + # type. The Polars reference is laid out as <section>/... under the base |
| 6 | + # url (e.g. dataframe/api/polars.DataFrame.count.html). Top-level members |
| 7 | + # (plain functions, datatypes, IO, config, ...) instead live flat under |
| 8 | + # api/ and are classified by name in #classify_api. |
| 9 | + SECTION_TYPES = { |
| 10 | + 'dataframe' => 'DataFrame', |
| 11 | + 'lazyframe' => 'LazyFrame', |
| 12 | + 'series' => 'Series', |
| 13 | + 'expressions' => 'Expressions', |
| 14 | + 'functions' => 'Functions', |
| 15 | + 'selectors' => 'Selectors', |
| 16 | + 'datatypes' => 'Data Types', |
| 17 | + 'datatype_expr' => 'Data Types', |
| 18 | + 'config' => 'Config', |
| 19 | + 'io' => 'Input/output', |
| 20 | + 'sql' => 'SQL', |
| 21 | + 'exceptions' => 'Exceptions', |
| 22 | + 'testing' => 'Testing', |
| 23 | + 'catalog' => 'Catalog', |
| 24 | + 'metadata' => 'Metadata', |
| 25 | + 'schema' => 'Schema', |
| 26 | + 'plugins' => 'Plugins' |
| 27 | + }.freeze |
| 28 | + |
| 29 | + def get_name |
| 30 | + name = at_css('h1').content.strip |
| 31 | + # This runs before clean_html removes the headerlink, so strip its |
| 32 | + # anchor character off the heading. |
| 33 | + name.sub! %r{\s*[#\u{00B6}]+\s*\z}, '' |
| 34 | + name |
| 35 | + end |
| 36 | + |
| 37 | + def get_type |
| 38 | + return 'Manual' if root_page? |
| 39 | + segment = slug.split('/').first |
| 40 | + return classify_api(get_name) if segment == 'api' |
| 41 | + SECTION_TYPES[segment] || 'Manual' |
| 42 | + end |
| 43 | + |
| 44 | + private |
| 45 | + |
| 46 | + # Members stored flat under api/ (top-level polars.* objects). |
| 47 | + def classify_api(name) |
| 48 | + case name |
| 49 | + when %r{\Apolars\.datatypes\.} then 'Data Types' |
| 50 | + when %r{\Apolars\.Config\b} then 'Config' |
| 51 | + when %r{\Apolars\.exceptions\.} then 'Exceptions' |
| 52 | + when %r{\Apolars\.testing\.} then 'Testing' |
| 53 | + when %r{\Apolars\.(api|plugins)\.} then 'Plugins' |
| 54 | + when %r{\Apolars\.io\.} then 'Input/output' |
| 55 | + when %r{\Apolars\.DataFrame\.} then 'DataFrame' |
| 56 | + when %r{\Apolars\.LazyFrame\.} then 'LazyFrame' |
| 57 | + when %r{\Apolars\.(read_|scan_|write_|from_)}, %r{\Apolars\.json_normalize\b} |
| 58 | + 'Input/output' |
| 59 | + else 'Functions' |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments