Class: Quandl::List
- Inherits:
-
Object
show all
- Defined in:
- lib/quandl/model/list.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(klass, values, meta) ⇒ List
Returns a new instance of List.
6
7
8
9
10
|
# File 'lib/quandl/model/list.rb', line 6
def initialize(klass, values, meta)
@klass = klass
@values = values.map { |v| klass.new(v, meta: meta) }
@meta = meta
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/quandl/model/list.rb', line 38
def method_missing(method_name, *args, &block)
return @meta[method_name.to_s] if @meta.key?(method_name.to_s)
return @meta[*args] if method_name.to_s == '[]' && @meta.key?(args[0].to_s)
return @values.method(method_name).call(*args, &block) if @values.respond_to?(method_name)
super
end
|
Instance Attribute Details
Returns the value of attribute meta.
3
4
5
|
# File 'lib/quandl/model/list.rb', line 3
def meta
@meta
end
|
#values ⇒ Object
Returns the value of attribute values.
4
5
6
|
# File 'lib/quandl/model/list.rb', line 4
def values
@values
end
|
Instance Method Details
#inspect ⇒ Object
32
33
34
|
# File 'lib/quandl/model/list.rb', line 32
def inspect
{ meta: @meta, values: @values }.to_s
end
|
#more_results? ⇒ Boolean
12
13
14
15
|
# File 'lib/quandl/model/list.rb', line 12
def more_results?
fail(QuandlError, "#{@klass} does not support pagination yet") if !@meta.key?('total_pages') && !@meta.key?('current_page')
@meta['total_pages'] > @meta['current_page']
end
|
#to_a ⇒ Object
17
18
19
|
# File 'lib/quandl/model/list.rb', line 17
def to_a
@values.map(&:to_a)
end
|
#to_csv ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/quandl/model/list.rb', line 21
def to_csv
fail(QuandlError, 'No values to export') if @values.empty?
CSV.generate do |csv|
csv << @values.first.column_names
@values.each do |row|
csv << row.to_a
end
end
end
|