Class: Macaroni::Plugin::Output::Wget

Inherits:
Object
  • Object
show all
Defined in:
lib/macaroni/plugin/output/wget.rb

Instance Method Summary collapse

Constructor Details

#initialize(dirpath = '.') ⇒ Wget

Returns a new instance of Wget.



8
9
10
# File 'lib/macaroni/plugin/output/wget.rb', line 8

def initialize(dirpath='.')
  @dirpath = dirpath
end

Instance Method Details

#exec(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/macaroni/plugin/output/wget.rb', line 12

def exec(data)
  FileUtils.mkdir_p(@dirpath) if !File.exists?(@dirpath)
  data.each do |url|
    uri = URI.parse(url)
    filename = (uri.path =~ %r[/$]) ? \
      'index.html' : File.basename(uri.path)
    filepath = File.join(@dirpath, filename)
    File.open filepath, 'wb' do |dst|
      open(url) do |src|
        dst.write(src.read)
      end
    end
  end
end