Class: Quandl::List
- Inherits:
-
Object
- Object
- Quandl::List
- Defined in:
- lib/quandl/model/list.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(klass, values, meta) ⇒ List
constructor
A new instance of List.
- #inspect ⇒ Object
- #more_results? ⇒ Boolean
- #to_a ⇒ Object
- #to_csv ⇒ Object
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, ) @klass = klass @values = values.map { |v| klass.new(v, meta: ) } @meta = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
rubocop:disable MethodMissing
39 40 41 42 43 44 |
# File 'lib/quandl/model/list.rb', line 39 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
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
3 4 5 |
# File 'lib/quandl/model/list.rb', line 3 def @meta end |
#values ⇒ Object (readonly)
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? raise(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 raise(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 |