Class: Quandl::Command::Tasks::Delete

Inherits:
Base
  • Object
show all
Defined in:
lib/quandl/command/tasks/delete.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options, #request_timer

Instance Method Summary collapse

Methods inherited from Base

#ask_yes_or_no, authenticated_users_only!, call, #call, command_name, configure, #current_user, #debug, description, disable!, disabled?, #error, #fatal, #force_yes?, #info, #initialize, #logger, options, #summarize, #summarize_hash, syntax, #table, #verbose?, warn_unauthenticated_users

Constructor Details

This class inherits a constructor from Quandl::Command::Tasks::Base

Instance Method Details

#confirmed?(dataset) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/quandl/command/tasks/delete.rb', line 52

def confirmed?(dataset)
  return true if force_yes?
  info summarize dataset.attributes.slice('source_code', 'code', 'name', 'from_date', 'to_date', 'column_names', 'created_at')
  ask_yes_or_no
end

#delete(code) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/quandl/command/tasks/delete.rb', line 30

def delete(code)
  return error("You must provide a code!") if code.blank?
  # find by code
  dataset = Quandl::Client::Dataset.find(code)
  # fail fast if dataset does not exist
  return error(table(Quandl::Client::HTTP_STATUS_CODES[404], code)) if dataset.nil?
  return report(dataset) unless dataset.exists?
  # confirm deletion
  return error("You must confirm deletion!") unless confirmed?(dataset)
  # delete if exists
  dataset.destroy if dataset.exists?
  # output status
  report(dataset)
end

#delete_each_argumentObject



15
16
17
18
19
20
# File 'lib/quandl/command/tasks/delete.rb', line 15

def delete_each_argument
  args.each do |code| 
    pool.process{ delete( code ) }
  end
  pool.shutdown
end

#delete_each_stdinObject



22
23
24
25
26
27
28
# File 'lib/quandl/command/tasks/delete.rb', line 22

def delete_each_stdin
  return error("Cannot delete datasets from STDIN unless --force-yes is set!") unless force_yes?
  $stdin.each_line do |code|
    pool.process{ delete( code.strip.rstrip ) }
  end
  pool.shutdown
end

#executeObject



8
9
10
11
12
13
# File 'lib/quandl/command/tasks/delete.rb', line 8

def execute
  # download using arguments when present
  return delete_each_argument if args.first.present?
  # otherwise delete using stdin
  delete_each_stdin
end

#report(dataset) ⇒ Object



45
46
47
48
49
50
# File 'lib/quandl/command/tasks/delete.rb', line 45

def report(dataset)
  # message
  m = table dataset.elapsed_request_time_ms, dataset.full_code
  # report
  dataset.status == 200 ? info(table("Deleted", m)) : error(table(dataset.human_status, m))
end