Class: CloudappExport::Exporter
- Inherits:
-
Object
- Object
- CloudappExport::Exporter
- Defined in:
- lib/cloudapp_export/exporter.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #export_all ⇒ Object
- #export_item(item) ⇒ Object
-
#initialize(items, options = {}) ⇒ Exporter
constructor
A new instance of Exporter.
- #on_log(&block) ⇒ Object
Constructor Details
#initialize(items, options = {}) ⇒ Exporter
Returns a new instance of Exporter.
5 6 7 8 9 |
# File 'lib/cloudapp_export/exporter.rb', line 5 def initialize(items, = {}) @items = items = @log_callbacks = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/cloudapp_export/exporter.rb', line 3 def items @items end |
Instance Method Details
#export_all ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cloudapp_export/exporter.rb', line 11 def export_all FileUtils.mkdir_p(download_dir) unless Dir.exist?(download_dir) items_count = items.count items.each_with_index do |item, index| percent = (index + 1).to_f / items_count * 100 log "[#{(index + 1).to_s.rjust(4, '0')} / #{items_count.to_s.rjust(4, '0')} #{percent.round.to_s.rjust(3, ' ')}%]" export_item(item) end end |
#export_item(item) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloudapp_export/exporter.rb', line 22 def export_item(item) log " #{item.name} -> #{item.filename}".ljust(80, ' ') filepath = "#{download_dir}/#{item.filename}" if File.exist?(filepath) log " SK #{item_filesize_human(item)}" elsif item['remote_url'].nil? || item['item_type'] == 'pending' log " SK No Remote URL" else begin log " DL" copy_file(item['remote_url'], filepath) log " #{item_filesize_human(item)}" rescue StandardError => error log " ER #{error.message}\n" error.backtrace.each { |line| log " #{line}\n" } end end log "\n" end |
#on_log(&block) ⇒ Object
43 44 45 |
# File 'lib/cloudapp_export/exporter.rb', line 43 def on_log(&block) @log_callbacks.push(block) end |