Skip to content

Commit

Permalink
Merge pull request #177 from nappex/naming-directory-structure
Browse files Browse the repository at this point in the history
Improve module naming and directory structure
  • Loading branch information
Glutexo authored Apr 7, 2023
2 parents c38b925 + 0578d0a commit f2c4aa4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/onigumo_downloader.ex → lib/onigumo/downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Onigumo.Downloader do
end

def create_file_name(url) do
Hash.md5(url, :hex)
Onigumo.Utilities.Hash.md5(url, :hex)
end

defp http_client() do
Expand Down
2 changes: 1 addition & 1 deletion lib/spider_html.ex → lib/spider/html.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Spider.HTML do
defmodule Onigumo.Spider.HTML do
def find_links(document) do
Floki.parse_document!(document)
|> Floki.find("a")
Expand Down
2 changes: 1 addition & 1 deletion lib/hash.ex → lib/utilities/hash.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Hash do
defmodule Onigumo.Utilities.Hash do
def md5(data, fmt) do
hash(:md5, data)
|> format(fmt)
Expand Down
8 changes: 4 additions & 4 deletions test/hash_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ defmodule HashTest do

for {data, hash_hex, _} <- @known_md5s do
test("hash MD5 #{inspect(data)} in hexadecimal") do
hash = Hash.md5(unquote(data), :hex)
hash = Onigumo.Utilities.Hash.md5(unquote(data), :hex)
assert(hash == unquote(hash_hex))
end
end

for {data, _, hash_bin} <- @known_md5s do
test("hash MD5 #{inspect(data)} in binary") do
hash = Hash.md5(unquote(data), :bin)
hash = Onigumo.Utilities.Hash.md5(unquote(data), :bin)
assert(hash == unquote(hash_bin))
end
end

for {format, hash} <- @formatted_hashes do
test("format #{inspect(@binary_hash)} in #{inspect(format)}") do
formatted = Hash.format(@binary_hash, unquote(format))
formatted = Onigumo.Utilities.Hash.format(@binary_hash, unquote(format))
assert(formatted == unquote(hash))
end
end

for {func, known_hash} <- @known_hashes do
test("hash #{inspect(@known_hash_data)} with #{inspect(func)}") do
computed_hash = Hash.hash(unquote(func), @known_hash_data)
computed_hash = Onigumo.Utilities.Hash.hash(unquote(func), @known_hash_data)
assert(computed_hash == unquote(known_hash))
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/onigumo_downloader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule OnigumoDownloaderTest do
input_url = "https://onigumo.local/hello.html"
created_file_name = Onigumo.Downloader.create_file_name(input_url)

expected_file_name = Hash.md5(input_url, :hex)
expected_file_name = Onigumo.Utilities.Hash.md5(input_url, :hex)
assert(created_file_name == expected_file_name)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/spider_html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ defmodule SpiderHtmlTest do
</body>
</html>)

describe("Spider.HTML.find_links/1") do
describe("Onigumo.Spider.HTML.find_links/1") do
test("find links in href attributes of 'a' tags") do
links = Spider.HTML.find_links(@html)
links = Onigumo.Spider.HTML.find_links(@html)
assert links == @urls
end
end
Expand Down

0 comments on commit f2c4aa4

Please sign in to comment.