Sha256: 376990b32b4128dcfdecf97b7a37f16497bcd654aa38308c8816a92c2d345976
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
module Ortega class File attr_reader :name, :destination def initialize(args = {}) @name = args[:name] @destination = args[:path] @extension = args[:extension] end def write(response) ::File.open(@destination, 'wb') do |io| content_length = response.header['Content-Length'] chunk_size = 0 puts "Downloading #{@name}" response.read_body do |chunk| io.write chunk chunk_size += chunk.size percent = ((chunk_size * 100) / content_length.to_i) $stdout.print "#{'#' * percent} #{percent.to_s.rjust(103 - percent, ' ')} %\r" $stdout.flush end end end def self.get_path(options) options = options.with_indifferent_access file = new(options) file.instance_eval do @name = @name.split('/').last @destination = ::File.join( "#{file.destination ? ::File.expand_path(file.destination) : '.'}", file.name) end return file end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ortega-0.0.6 | lib/ortega/file.rb |