travis-ci
35 of 35 new or added lines in 4 files covered. (100.0%)
1361 of 1456 relevant lines covered (93.48%)
4.25 hits per line
1 |
# frozen_string_literal: true
|
|
2 |
|
|
|
require "digest/sha2"
|
1✔ |
|
require "murmurhash3"
|
1✔ |
5 |
|
|
|
module Mihari |
1✔ |
|
class HTML |
1✔ |
|
attr_reader :path
|
1✔ |
9 |
|
|
|
def initialize(path) |
1✔ |
|
@path = path
|
1✔ |
12 |
end
|
|
13 |
|
|
|
def exists? |
1✔ |
|
return false unless path |
1✔ |
16 |
|
|
|
File.exist? path
|
1✔ |
18 |
end
|
|
19 |
|
|
|
def sha256 |
1✔ |
|
Digest::SHA256.hexdigest data |
1✔ |
22 |
end
|
|
23 |
|
|
|
def md5 |
1✔ |
|
Digest::MD5.hexdigest data |
1✔ |
26 |
end
|
|
27 |
|
|
|
def mmh3 |
1✔ |
|
hash = MurmurHash3::V32.str_hash(data) |
1✔ |
|
if (hash & 0x80000000).zero? |
1✔ |
|
hash |
× |
32 |
else
|
|
|
-((hash ^ 0xFFFFFFFF) + 1) |
1✔ |
34 |
end
|
|
35 |
end
|
|
36 |
|
|
|
private |
1✔ |
38 |
|
|
|
def data |
1✔ |
|
File.read path
|
3✔ |
41 |
end
|
|
42 |
end
|
|
43 |
end
|