Class: Jaxx::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/jaxx/download.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Download

Returns a new instance of Download.



8
9
10
# File 'lib/jaxx/download.rb', line 8

def initialize args = {}
  @process = Process.new(args)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/jaxx/download.rb', line 6

def filename
  @filename
end

#processObject (readonly)

Returns the value of attribute process.



6
7
8
# File 'lib/jaxx/download.rb', line 6

def process
  @process
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jaxx/download.rb', line 24

def execute
  process.start do |storage|
    directory = storage.directories.get(process.bucket)

    files(directory).each do |target, source|
      File.open(target, 'wb') do |file|
        directory.files.get(source) {|chunk, byt_remain, byt_total| file.write(chunk) }
      end
    end
  end
end

#files(directory) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jaxx/download.rb', line 12

def files directory
  if process.file.match(%r{/$})
    directory.files.inject({}) do |hsh, f|
      key = f.key.gsub(process.file, '')
      hsh[key] = f.key if !key.empty? and f.key.match(process.file)
      hsh
    end
  else
    { File.basename(process.file) => process.file }
  end
end