-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
231 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
defmodule Greetings do | ||
@moduledoc false | ||
|
||
def start do | ||
IO.puts( | ||
" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
defmodule Parse do | ||
@moduledoc """ | ||
This module parses the given html string and counts how many CSS selectors | ||
there are in it. | ||
""" | ||
|
||
@doc """ | ||
Asyncronously returns a map of the given CSS selectors with their count. | ||
## Parameters | ||
- `body`: html page as string | ||
- `queries`: a list of valid CSS selectors as string | ||
- `pid`: the pid which will receive the output | ||
""" | ||
def start(body, queries, pid) do | ||
spawn __MODULE__, :parse, [body, queries, pid] | ||
end | ||
|
||
@doc """ | ||
Returns a map of the given CSS selectors with their count. | ||
## Parameters | ||
- `body`: html page as string | ||
- `queries`: a list of valid CSS selectors as string | ||
""" | ||
def start(body, queries) do | ||
parse(body, queries) | ||
end | ||
|
||
def parse(body, queries) do | ||
@doc false | ||
def parse(body, queries, pid) do | ||
send pid, parse(body, queries) | ||
end | ||
|
||
defp parse(body, queries) do | ||
Enum.reduce(queries, %{}, fn(q, acc) -> | ||
items = Floki.find(body, q) | ||
Map.put(acc, q, Enum.count(items)) | ||
end) | ||
end | ||
|
||
def parse(body, queries, pid) do | ||
send pid, parse(body, queries) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.