Class: Quandl::Command::Tasks::Download
- Inherits:
-
Base
- Object
- Base
- Quandl::Command::Tasks::Download
show all
- Defined in:
- lib/quandl/command/tasks/download.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
Instance Method Details
#collapse ⇒ Object
88
89
90
|
# File 'lib/quandl/command/tasks/download.rb', line 88
def collapse
options.collapse
end
|
#data_params ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/quandl/command/tasks/download.rb', line 96
def data_params
params = {}
self.class.options.each do |class_type, opts|
opts.each do |name, desc|
if options.is_a?(OpenStruct)
params[name] = self.options.send(name)
else
params[name] = self.options[name] if self.options[name].present?
end
end
end
params
end
|
#download(code) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/quandl/command/tasks/download.rb', line 52
def download(code)
timer = Time.now
dataset = Quandl::Client::Dataset.find( code )
return error(table(Quandl::Client::HTTP_STATUS_CODES[404], code)) if dataset.nil?
dataset.data.assign_attributes(data_params) unless dataset.blank?
if !dataset.exists? && !dataset.valid?
return error( table( dataset.human_status, code, dataset.elapsed_request_time_ms ) )
end
elapsed = timer.elapsed_ms
qdf = dataset.to_qdf
mutex.synchronize{
debug("# #{dataset.try(:full_url)} downloaded in #{elapsed}")
info(qdf)
}
true
end
|
#download_each_argument ⇒ Object
38
39
40
41
42
43
|
# File 'lib/quandl/command/tasks/download.rb', line 38
def download_each_argument
args.each do |code|
pool.process{ download(code) }
end
pool.shutdown
end
|
#download_each_stdin ⇒ Object
45
46
47
48
49
50
|
# File 'lib/quandl/command/tasks/download.rb', line 45
def download_each_stdin
$stdin.each_line do |code|
pool.process{ download(code.strip.rstrip) }
end
pool.shutdown
end
|
#execute ⇒ Object
31
32
33
34
35
36
|
# File 'lib/quandl/command/tasks/download.rb', line 31
def execute
return download_each_argument if args.first.present?
download_each_stdin
end
|
#order ⇒ Object
84
85
86
|
# File 'lib/quandl/command/tasks/download.rb', line 84
def order
options.order
end
|
92
93
94
|
# File 'lib/quandl/command/tasks/download.rb', line 92
def transform
options.transform
end
|
#trim_end ⇒ Object
80
81
82
|
# File 'lib/quandl/command/tasks/download.rb', line 80
def trim_end
options.trim_end
end
|
#trim_start ⇒ Object
76
77
78
|
# File 'lib/quandl/command/tasks/download.rb', line 76
def trim_start
options.trim_start
end
|