add detec_format and validate functions
This commit is contained in:
1 parent
12310ce2dc
commit
67a974f947
1 file changed
+30
-2
+30
-2
@@ -2,7 +2,35 @@ defmodule FeedReader do
|
|||||||
@moduledoc """
|
@moduledoc """
|
||||||
Standalone feed fetching and parsing library.
|
Standalone feed fetching and parsing library.
|
||||||
|
|
||||||
The public parsing and fetching APIs will be added incrementally. This
|
This module exposes the public format detection and validation helpers.
|
||||||
module is the stable namespace for the package.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@typedoc "`:rss`, `:atom`, `:rdf`, `:unknown`, or a custom format's atom ID."
|
||||||
|
@type format_id :: atom()
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Detects a format from a bounded binary prefix.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
- `:max_detection_bytes` — `pos_integer()`; default `65_536`; invalid values yield `:unknown`.
|
||||||
|
- `:formats` — list of modules, checked after RSS, Atom, and RDF in list order; duplicates removed.
|
||||||
|
Custom modules provide `matches_prefix?/1` and `id/0`.
|
||||||
|
"""
|
||||||
|
@spec detect_format(binary(), keyword()) :: format_id()
|
||||||
|
def detect_format(content, opts \\ []) do
|
||||||
|
FeedReader.FormatDetector.detect(content, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Checks only the bounded-prefix signature for a format ID or module.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
- `:max_detection_bytes` — `pos_integer()`, default `65_536`; invalid values yield `false`.
|
||||||
|
- `:formats` — custom modules used to resolve custom format IDs. Modules provide
|
||||||
|
`matches_prefix?/1` and `id/0`; passing the format module directly also works.
|
||||||
|
"""
|
||||||
|
@spec validate(binary(), atom() | module(), keyword()) :: boolean()
|
||||||
|
def validate(content, format, opts \\ []) do
|
||||||
|
FeedReader.FormatDetector.validate(content, format, opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user