Class: Drophunter::Worker

Inherits:
Struct
  • Object
show all
Defined in:
lib/drophunter/worker.rb

Constant Summary collapse

ALLOWED_CHARS =
[*"a".."z", *"A".."Z"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#strategyObject

Returns the value of attribute strategy

Returns:

  • (Object)

    the current value of strategy



8
9
10
# File 'lib/drophunter/worker.rb', line 8

def strategy
  @strategy
end

Instance Method Details

#default_strategyObject



21
22
23
24
25
# File 'lib/drophunter/worker.rb', line 21

def default_strategy
  ALLOWED_CHARS.repeated_permutation(4).each do |id_as_array|
    save_file(id_as_array.join)
  end
end

#random_strategy(&block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/drophunter/worker.rb', line 27

def random_strategy(&block)
  Enumerator.new do |enumerator|
    loop do
      enumerator.yield(4.times.map { ALLOWED_CHARS[Random.rand(0..ALLOWED_CHARS.length)] }.join)
    end
  end.each { |id| block.call(id) }
end

#runObject



11
12
13
# File 'lib/drophunter/worker.rb', line 11

def run
  send("#{strategy || :default}_strategy")
end

#save_file(id) ⇒ Object



15
16
17
18
19
# File 'lib/drophunter/worker.rb', line 15

def save_file(id)
  default_saver = Drophunter::Savers::Local.new

  Drophunter::Page.new(id).save(Drophunter::FileTypes::Image, default_saver)
end