Class: AwsWhitepaperDownloader::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_whitepaper_downloader/downloader.rb

Constant Summary collapse

WHITE_PAPPER_ROOT_DIR =
"#{__dir__}/white pappers"

Instance Method Summary collapse

Constructor Details

#initializeDownloader

Returns a new instance of Downloader.



6
7
# File 'lib/aws_whitepaper_downloader/downloader.rb', line 6

def initialize
end

Instance Method Details

#run(hash, download_path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aws_whitepaper_downloader/downloader.rb', line 9

def run( hash, download_path )
  download_path = download_path ? "#{ download_path }/white pappers" : WHITE_PAPPER_ROOT_DIR
  check_dir_created( nil, download_path )

  hash.each_pair do |key, value|
    current_dir = check_dir_created( key, download_path )
    case value['type']
    when 'normal'
      Dir.chdir current_dir
      puts 'normal'
      hash.each_pair do |k1, v1|
        next if k1 == 'type'
        v1.each do |k2, v2|
          next if k2 == 'type'
          download( k2, v2,"#{current_dir}/#{v2}")
        end
      end
    when 'nested'
      puts 'nested'
      value.each_pair do |k1, v1|
        next if k1 == 'type'
        nested_dir = check_dir_created( k1, current_dir )
        Dir.chdir( nested_dir )

        v1.each do |k2, v2|
          next if k2 == 'type'
          download( k2, v2,"#{nested_dir}/#{v2}")
        end
      end
    end

  end
end