Skip to content

Commit

Permalink
moved URL to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonyfox committed May 20, 2019
1 parent 9fb1053 commit 607f7f3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/scrape/ir/feed.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Scrape.IR.Feed do
alias Scrape.Tools.Tree
alias Scrape.Tools.URL

@doc """
Extract the (best) title from the feed.
Expand Down Expand Up @@ -64,7 +65,7 @@ defmodule Scrape.IR.Feed do

defp normalize(nil), do: nil
defp normalize(""), do: nil
defp normalize(url), do: url |> Scrape.IR.URL.base()
defp normalize(url), do: url |> URL.base()

@doc """
Returns the list of all feed items.
Expand Down
3 changes: 2 additions & 1 deletion lib/scrape/ir/feed_item.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Scrape.IR.FeedItem do
alias Scrape.Tools.Tree
alias Scrape.Tools.URL

@doc """
Extract the (best) title from the feed item.
Expand Down Expand Up @@ -155,6 +156,6 @@ defmodule Scrape.IR.FeedItem do
defp normalize_to_string(_), do: nil

# merge an relative url into an absolute url if possible
defp normalize_url(link, url) when is_binary(url), do: Scrape.IR.URL.merge(link, url)
defp normalize_url(link, url) when is_binary(url), do: URL.merge(link, url)
defp normalize_url(_, _), do: nil
end
9 changes: 5 additions & 4 deletions lib/scrape/ir/html.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Scrape.IR.HTML do
alias Scrape.Tools.DOM
alias Scrape.Tools.URL

@doc """
Extract the best possible title from a HTML document (string or DOM) or nil.
Expand Down Expand Up @@ -83,7 +84,7 @@ defmodule Scrape.IR.HTML do
def image_url(dom, url \\ "") do
case DOM.first(dom, @image_url_queries) do
nil -> nil
match -> Scrape.IR.URL.merge(match, url)
match -> URL.merge(match, url)
end
end

Expand Down Expand Up @@ -113,7 +114,7 @@ defmodule Scrape.IR.HTML do
def icon_url(dom, url \\ "") do
case DOM.first(dom, @icon_url_queries) do
nil -> nil
match -> Scrape.IR.URL.merge(match, url)
match -> URL.merge(match, url)
end
end

Expand All @@ -135,8 +136,8 @@ defmodule Scrape.IR.HTML do
list = feed_meta_tag(dom) ++ feed_inline(dom)

list
|> Enum.filter(&Scrape.IR.URL.is_http?(&1))
|> Enum.map(&Scrape.IR.URL.merge(&1, url))
|> Enum.filter(&URL.is_http?(&1))
|> Enum.map(&URL.merge(&1, url))
|> Enum.uniq()
end

Expand Down
8 changes: 4 additions & 4 deletions lib/scrape/ir/url.ex → lib/scrape/tools/url.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Scrape.IR.URL do
defmodule Scrape.Tools.URL do
@moduledoc """
Simple utility functions to extract information from URLs.
"""
Expand All @@ -8,7 +8,7 @@ defmodule Scrape.IR.URL do
aboslute ones.
## Example
iex> Scrape.IR.URL.merge("/path", "http://example.com")
iex> URL.merge("/path", "http://example.com")
"http://example.com/path"
"""

Expand All @@ -30,10 +30,10 @@ defmodule Scrape.IR.URL do
Checks if a given string actually represents an URL.
## Example
iex> Scrape.IR.URL.is_http?("http://example.com")
iex> URL.is_http?("http://example.com")
true
iex> Scrape.IR.URL.is_http?("example")
iex> URL.is_http?("example")
false
"""

Expand Down

0 comments on commit 607f7f3

Please sign in to comment.