Class: Bloomed::PW

Inherits:
Object
  • Object
show all
Includes:
MsgPackable::Bloomed
Defined in:
lib/bloomed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MsgPackable::Bloomed

#from_msgpack_ext, included, #to_msgpack, #to_msgpack_ext

Constructor Details

#initialize(top: 100_000, false_positive_probability: 0.001, cache_dir: nil) ⇒ PW



18
19
20
21
22
23
24
25
# File 'lib/bloomed.rb', line 18

def initialize(top: 100_000,
               false_positive_probability: 0.001,
               cache_dir: nil)
  @cache_dir = cache_dir || File.join(File.dirname(__FILE__), "dump")
  @top = top
  @false_positive_probability = false_positive_probability
  @bloom = prepare
end

Instance Attribute Details

#bloomObject (readonly)

Returns the value of attribute bloom.



12
13
14
# File 'lib/bloomed.rb', line 12

def bloom
  @bloom
end

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



12
13
14
# File 'lib/bloomed.rb', line 12

def cache_dir
  @cache_dir
end

#false_positive_probabilityObject (readonly)

Returns the value of attribute false_positive_probability.



12
13
14
# File 'lib/bloomed.rb', line 12

def false_positive_probability
  @false_positive_probability
end

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/bloomed.rb', line 12

def filename
  @filename
end

#topObject (readonly)

Returns the value of attribute top.



12
13
14
# File 'lib/bloomed.rb', line 12

def top
  @top
end

Instance Method Details

#memory_size_bytesObject



31
32
33
34
# File 'lib/bloomed.rb', line 31

def memory_size_bytes
  require "objspace"
  ObjectSpace.memsize_of(@bloom)
end

#pwned?(pw) ⇒ Boolean



27
28
29
# File 'lib/bloomed.rb', line 27

def pwned?(pw)
  @bloom.include?(Digest::SHA1.hexdigest(pw).upcase)
end