Microdata v0.2.4 Microdata.Helpers View Source
Microdata.Helpers
is a module for generic parsing helpers (ie those not coupled to the parsing mechanism).
For example, certain tags require their values to be absolute URLs.
Link to this section Summary
Functions
Helper function to determine if a passed URL is absolute. Returns true/false bools
Parse item id from a provided string
Parse item types from a space-separated string
Parse property names from a provided string
Validates that URLs include scheme & host
Link to this section Functions
Helper function to determine if a passed URL is absolute. Returns true/false bools.
Examples
iex> Microdata.Helpers.absolute_url?(nil)
false
iex> Microdata.Helpers.absolute_url?("path/to/page")
false
iex> Microdata.Helpers.absolute_url?("/path/to/page")
false
iex> Microdata.Helpers.absolute_url?("https://google.com")
true
Parse item id from a provided string.
Examples
iex> Microdata.Helpers.parse_item_id(nil)
nil
iex> Microdata.Helpers.parse_item_id("\r foo \n")
URI.parse("foo")
iex> Microdata.Helpers.parse_item_id("https://google.com")
URI.parse("https://google.com")
Parse item types from a space-separated string.
Examples
iex> Microdata.Helpers.parse_item_types(nil)
[]
iex> Microdata.Helpers.parse_item_types("foo")
["foo"]
iex> Microdata.Helpers.parse_item_types("foo bar")
["foo", "bar"]
iex> Microdata.Helpers.parse_item_types("\n\nfoo bar baz \n ")
["foo", "bar", "baz"]
Parse property names from a provided string.
Examples
iex> Microdata.Helpers.parse_property_names(nil)
nil
iex> Microdata.Helpers.parse_property_names("bar", %Microdata.Item{types: MapSet.new(["foo"])})
["foo/bar"]
iex> Microdata.Helpers.parse_property_names("\rbar baz bar \n", %Microdata.Item{types: MapSet.new(["foo"])})
["foo/bar", "foo/baz"]
Link to this function
parse_property_names(string, item)
View Source
parse_property_names(String.t(), Microdata.Item.t()) :: [String.t()]
Validates that URLs include scheme & host
Examples
iex> Microdata.Helpers.validate_url("foo")
{:error, "No scheme"}
iex> Microdata.Helpers.validate_url("http://")
{:error, "No host"}
iex> Microdata.Helpers.validate_url("http://foo.com")
{:ok, "http://foo.com"}